由于元数据表值删除而导致批次卡住

时间:2019-06-06 15:46:02

标签: hibernate spring-boot spring-batch

当多个批处理同时运行且处理大量数据时,我的Spring批处理应用程序被卡住了。获取以下异常

Blocked resource    ridlock fileid=1 pageid=69265493 dbid=6 id=lock2a36e0c00 mode=X associatedObjectId=72057594039631872 
Blocked database    *****

Blocking Host (User)    ZNAPCDP1842V (myuser) 
Blocking application    jTDS 

Blocking statement  N/A 
Blocking batch/sp   delete from BATCH_STEP_EXECUTION_SEQ where ID < 145678

我正在使用Spring Boot版本-1.2.5,Hibernate 4.3.5 我没有使用基于XML的配置

我有以下链接中描述的方法

Multiple Spring Batch jobs executing concurrently causing deadlocks in the Spring Batch metadata tables

当我使用基于Java的配置时,我已经按照以下步骤进行操作


@Configuration
@EnableBatchProcessing(modular=true)
public class AppConfig extends DefaultBatchConfigurer{

    @Autowired
    DataSource datasource; 

    @Autowired
    PlatformTransactionManager transactionManager; 

    @Autowired
    public void setDataSource(DataSource datasource) { 
        this.transactionManager = new DataSourceTransactionManager(datasource);
    }


    @Override
    public JobRepository createJobRepository() throws Exception{

        setDataSource(this.datasource);

        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(datasource);
        factory.setTransactionManager(transactionManager);
        factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
        factory.setTablePrefix("BATCH_");
        factory.setDatabaseType("SQLSERVER");
        factory.setMaxVarCharLength(1000);
        return factory.getObject();

    }

//Registering my job configuration beans
    }

它工作到某个时刻并从大多数休眠查询中获取数据,但在某个时刻抛出低于异常的信息  “ java.lang.ClassCastException:org.hibernate.action.internal.DelayedPostInsertIdentifier无法转换为java.lang.Long”

这次它尝试从下面的查询中读取数据

@Query("SELECT tb FROM TBodyPart tb " +                             
            "WHERE tb.tPlan=?1 and LTRIM(RTRIM(tb.iBodyPart)) = LTRIM(RTRIM(?2)) and LTRIM(RTRIM(tb.iName))=LTRIM(RTRIM(?3)) and (LTRIM(RTRIM(tb.iOrientation))=LTRIM(RTRIM(?4)) OR tb.iOrientation=?4 )")
    public TBodyPart findDetailsMethod(TPlan tPlanId,String bpName,String iName,String iOrientation);

这里可能出什么问题了?为什么它可以很好地获取所有其他查询,但仅对此查询抛出异常?

注意:如果我删除在AppConfig类中添加的内容以避免批次卡住的问题,则上述查询可以正常工作。 (factory.setIsolationLevelForCreate(“ ISOLATION_REPEATABLE_READ”);)。我也尝试过其他隔离级别

编辑前的配置文件


@Configuration
@EnableBatchProcessing(modular=true)
public class AppConfig{
@Bean
    public ApplicationContextFactory myJobContext(){
        return new GenericApplicationContextFactory(MyJobConfiguration.class);
    }
}

编辑后


@Autowired
    DataSource datasource; 

    @Autowired
    PlatformTransactionManager transactionManager; 

    @Autowired
    public void setDataSource(DataSource datasource) { 
        this.transactionManager = new DataSourceTransactionManager(datasource);
    }


    @Override
    public JobRepository createJobRepository() throws Exception{

        setDataSource(this.datasource);

        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(datasource);
        factory.setTransactionManager(transactionManager);
        factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
        factory.setTablePrefix("BATCH_");
        factory.setDatabaseType("SQLSERVER");
        factory.setMaxVarCharLength(10000);
        return factory.getObject();

    }
}

0 个答案:

没有答案
相关问题