spring+mybatis第一次查询速度非常慢,差不多1分多钟,麻烦大神帮看一下

代码搬晕工 2017-06-01 11:00:56
DataSource配置

<!-- dataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<!-- 参数 -->
<!--maxActive: 最大连接数量-->
<property name="maxActive" value="150"/>
<!--minIdle: 最小空闲连接-->
<property name="minIdle" value="5"/>
<!--maxIdle: 最大空闲连接-->
<property name="maxIdle" value="20"/>
<!--initialSize: 初始化连接-->
<property name="initialSize" value="30"/>
<!-- 连接被泄露时是否打印 -->
<property name="logAbandoned" value="true"/>
<!--removeAbandoned: 是否自动回收超时连接-->
<property name="removeAbandoned" value="true"/>
<!--removeAbandonedTimeout: 超时时间(以秒数为单位)-->
<property name="removeAbandonedTimeout" value="6000000"/>
<!--maxWait: 超时等待时间以毫秒为单位 -->
<property name="maxWait" value="20000"/>
<!-- 在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位. -->
<property name="timeBetweenEvictionRunsMillis" value="3600000"/>
<!-- 在每次空闲连接回收器线程(如果有)运行时检查的连接数量 -->
<property name="numTestsPerEvictionRun" value="50"/>
<!-- 1000 * 60 * 30 连接在池中保持空闲而不被空闲连接回收器线程-->
<property name="minEvictableIdleTimeMillis" value="120000"/>
<!-- MySQL连接时,服务器默认的“wait_timeout”是8小时,也就是说一个connection空闲超过8个小时,
Mysql将自动断开该connection。connections如果空闲超过8小时,Mysql将其断开,
而DBCP并不知道该connection已经失效,如果这时有Client请求connection,
DBCP将该失效的Connection提供给Client,将会造成异常。 -->
<property name="validationQuery" value="SELECT 1"></property>
<property name="testWhileIdle" value="true"></property>
<property name="testOnBorrow" value="true"></property>

</bean>

<!-- 事务配置 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes >
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="query*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="get*" propagation="SUPPORTS" />
<!-- 出现异常回滚 -->
<tx:method name="*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>

<!--第一个 * —— 通配 任意返回值类型
第二个 * —— 通配 包com.evan.crm.service下的任意class
第三个 * —— 通配 包com.evan.crm.service下的任意class的任意方法
第四个 .. —— 通配 方法可以有0个或多个参数
-->
<aop:config >
<aop:pointcut expression="execution(* com.xxxx.service..*.*(..) )" id="service"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="service"/>
</aop:config>

<tx:annotation-driven />


serviceImpl 查询,因为我用了mybatis自动生成工具生成dao,所以参数中间有一层example

UserAccountExample example = new UserAccountExample();
example.or().andCUserAccountsEqualTo(account);
//就这句查询时非常慢
List<UserAccount> list = userAccountMapper.selectByExample(example);



...全文
1555 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
北冥友余 2017-09-01
  • 打赏
  • 举报
回复
楼主,你解决了吗?新人想请教你这个问题
龙卷风Style 2017-06-02
  • 打赏
  • 举报
回复
你在数据库中执行这个SQL语句用时多少,对比一下看看
X元素 2017-06-01
  • 打赏
  • 举报
回复
通过日志在数据查询位置 ,排查一下查询时间问题。
xwn_2016 2017-06-01
  • 打赏
  • 举报
回复
数据量多大? 加索引了没
HinanaiTenshi 2017-06-01
  • 打赏
  • 举报
回复
排除sql的问题了没?
代码搬晕工 2017-06-01
  • 打赏
  • 举报
回复
代码搬晕工 2017-06-01
  • 打赏
  • 举报
回复
引用 9 楼 HinanaiTenshi 的回复:
输出一下service里调用dao方法消耗的时间....就在dao前后减一下,看看多少毫秒
输过了,差不多1分钟。。。
HinanaiTenshi 2017-06-01
  • 打赏
  • 举报
回复
输出一下service里调用dao方法消耗的时间....就在dao前后减一下,看看多少毫秒
代码搬晕工 2017-06-01
  • 打赏
  • 举报
回复
引用 6 楼 getdate 的回复:
"userAccountMapper.selectByExample(example);" 贴出XML来看看

<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.model.UserAccountExample" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 04 14:11:42 CST 2017.
    -->
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from i_user_account
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
    <if test="limitValue" >
       limit ${value}, ${secondValue}
    </if>
  </select>

<sql id="Example_Where_Clause" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 04 14:11:42 CST 2017.
    -->
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
代码搬晕工 2017-06-01
  • 打赏
  • 举报
回复
引用 2 楼 HinanaiTenshi 的回复:
排除sql的问题了没?
就10多条数据
getdate 2017-06-01
  • 打赏
  • 举报
回复
"userAccountMapper.selectByExample(example);" 贴出XML来看看
代码搬晕工 2017-06-01
  • 打赏
  • 举报
回复
引用 2 楼 HinanaiTenshi 的回复:
排除sql的问题了没?
dao和model是用mybatis生成的,不存在sql问题,我觉得是配置问题

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧