Druid连接池问题

这是什么鬼 发布于 2017/07/25 15:52
阅读 176
收藏 0

@wenshao 你好,想跟你请教个问题:

最近用的Druid连接池配合tomocat和mybatis做了一个项目,当并发量稍高的时候老是会出现以下这两种问题:

com.mysql.jdbc.exceptions.jdbc4.MySQLQueryInterruptedException:

Query execution was interrupted

 

Communications link failure

The last packet successfully received from the server was 163,890 milliseconds ago.

这是mybatis的配置

<settings>
    <!-- 全局映射器启用缓存 -->
    <setting name="cacheEnabled" value="false"/>
    <!-- 查询时,关闭关联对象即时加载以提高性能 -->
    <setting name="lazyLoadingEnabled" value="false"/>
    <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
    <setting name="multipleResultSetsEnabled" value="true"/>
    <!-- 允许使用列标签代替列名 -->
    <setting name="useColumnLabel" value="true"/>
    <!-- 不允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
    <setting name="useGeneratedKeys" value="false"/>
    <!-- 给予被嵌套的resultMap以字段-属性的映射支持 FULL,PARTIAL -->
    <setting name="autoMappingBehavior" value="PARTIAL"/>
    <!-- 对于批量更新操作缓存SQL以提高性能 BATCH,SIMPLE -->
    <setting name="defaultExecutorType" value="SIMPLE" />
    <!-- 数据库超过25000秒仍未响应则超时 -->
    <setting name="defaultStatementTimeout" value="25000" />
    <!-- Allows using RowBounds on nested statements -->
    <setting name="safeRowBoundsEnabled" value="false"/>
    <!-- Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn. -->
    <setting name="mapUnderscoreToCamelCase" value="true"/>
    <!-- MyBatis uses local cache to prevent circular references and speed up repeated nested queries. By default (SESSION) all queries executed during a session are cached. If localCacheScope=STATEMENT
        local session will be used just for statement execution, no data will be shared between two different calls to the same SqlSession. -->
    <setting name="localCacheScope" value="SESSION"/>
    <!-- Specifies the JDBC type for null values when no specific JDBC type was provided for the parameter. Some drivers require specifying the column JDBC type but others work with generic values
        like NULL, VARCHAR or OTHER. -->
    <setting name="jdbcTypeForNull" value="OTHER"/>
    <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->
    <setting name="aggressiveLazyLoading" value="true"/>
    <!-- Specifies which Object's methods trigger a lazy load -->
    <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
    <!--<setting name="logImpl" value="LOG4J"/>-->
    <!--<setting name="logImpl" value="STDOUT_LOGGING"/>-->
</settings>

这是druid的配置:

jdbc.maxActive=500
jdbc.minIdle=5
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=180
jdbc.logAbandoned=true
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
      destroy-method="close">
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="driverClassName" value="${jdbc.driver}"/>
    <property name="maxActive" value="${jdbc.maxActive}"/>
    <property name="minIdle" value="${jdbc.minIdle}"/>
    <!-- 超过时间限制是否回收 -->
    <property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
    <!-- 超时时间;单位为秒。180秒=3分钟 -->
    <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
    <!-- 关闭abanded连接时输出错误日志 -->
    <property name="logAbandoned" value="${jdbc.logAbandoned}"/>
    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
    <property name="timeBetweenEvictionRunsMillis" value="60000"/>
    <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
    <property name="minEvictableIdleTimeMillis" value="300000"/>
    <property name="testWhileIdle" value="true"/>
    <property name="validationQuery" value="SELECT 'x'"/>
    <property name="testOnReturn" value="true"/>
    <!-- 配置监控统计拦截的filters -->
    <property name="filters" value="stat"/>
</bean>

tomocat的连接:

<Connector port="7080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="7443"/>
加载中
0
依然菜刀
依然菜刀

druid的sql有一个执行超时的设置!好像是设置每个connection的最大持有时间,防止sql执行过慢导致系统卡死的。。。你去看下呢

返回顶部
顶部