Spring Mybatis insert在任务中完成时冻结

Spring Mybatis insert在任务中完成时冻结,spring,mybatis,spring-mybatis,Spring,Mybatis,Spring Mybatis,我定义了一个sql会话: <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"

我定义了一个sql会话:

<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0" ref="sqlSessionFactory" />
    <constructor-arg index="1" value="BATCH" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="..." />
</bean>

<bean id="taskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="queueCapacity" value="25" />
</bean>

现在,在我的服务中,我必须在表上进行一些选择,并在不同的表中插入一些内容

@Transactional
public class MyWebService{
   @Autowired
   private TaskExecutor executor;
   @Autowired
   private SelectTableMapper sm;
   @Autowired
   private InsertTableMapper it;

   public void service(){
     int rowCount = ...//getting row count
     int batch = rowCount/numThreads;
     //computing an interval for each thread with non overlapping rows
     for(int i=0;i<numThread;i++)
        executor.execute(new MyTask(//interval//));

     ..waiting for all tasks and finally returning
   }

   private class MyTask implements Runnable{

         public void run(){
              List<Row> rows = sm.select(//interval//);
              for(Row row : rows){
                   if(//some condition//)
                       it.insert(row); //if I comment here it successfully completes

              }

         }

   }

}
@Transactional
公共类MyWebService{
@自动连线
私人任务执行者;
@自动连线
私有SelectTableMapper sm;
@自动连线
私有InsertTableMapper it;
公共服务{
int rowCount=…//正在获取行计数
int batch=rowCount/numThreads;
//计算具有非重叠行的每个线程的间隔

对于(int i=0;ii很难说没有看到
InsertTableMapper.insert
语句。您可以通过在一行中创建几个stacktrace转储来诊断此问题(通过jstack/jconsole/jvisualmv)当程序冻结时。如果stacktrace显示程序在调用数据库时确实冻结了,那么您需要数据库级工具来查看冻结的查询试图获取什么锁以及其他事务持有什么锁。这取决于数据库(在postgresql中,您应该使用pg_stat_活动和pg_锁来完成)。