2

我正在使用带有石英的 Spring Batch。我有一个 bean destroy 方法,它在关闭 tomcat 时重置数据库中的一些标志。由于以下异常,不调用destroy方法:

2013-06-18 18:11:16,505  INFO | schedulerFactoryBean_Worker-3 | org.quartz.core.JobRunShell  | Job DEFAULT.fundAdditionRequestJobDetail threw a JobExecutionException:  
org.quartz.JobExecutionException: Error while executing Spring Batch job 
at com.inmobi.sap.quartz.AbstractQuartzLauncher.executeInternal(AbstractQuartzLauncher.java:88) ~[AbstractQuartzLauncher.class:na]
    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) ~[spring-context-support-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213) ~[quartz-2.1.7.jar:na]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-2.1.7.jar:na]
Caused by: java.lang.NullPointerException: null
    at org.apache.commons.logging.impl.SLF4JLocationAwareLog.isTraceEnabled(SLF4JLocationAwareLog.java:60) ~[jcl-over-slf4j-1.6.1.jar:1.1.1]
    at org.springframework.transaction.support.TransactionSynchronizationManager.getResource(TransactionSynchronizationManager.java:139) ~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doGetTransaction(DataSourceTransactionManager.java:180) ~[spring-jdbc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:336) ~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417) ~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255) ~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) ~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) ~[spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at com.sun.proxy.$Proxy11.update(Unknown Source) ~[na:na]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:340) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) ~[spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
    at com.inmobi.sap.quartz.AbstractQuartzLauncher.executeInternal(AbstractQuartzLauncher.java:84) ~[AbstractQuartzLauncher.class:na]
    ... 3 common frames omitted 

2013-06-18 18:11:16,508 ERROR | schedulerFactoryBean_Worker-3 | org.quartz.core.ErrorLogger   | An error occured while marking executed job complete. job= 'DEFAULT.fundAdditionRequestJobDetail' 
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.schedulerFactoryBean': java.lang.NullPointerException
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:173) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3788) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3760) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggeredJobComplete(JobStoreSupport.java:3000) ~[quartz-2.1.7.jar:na]
    at org.quartz.core.QuartzScheduler.notifyJobStoreJobComplete(QuartzScheduler.java:1753) ~[quartz-2.1.7.jar:na]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:281) ~[quartz-2.1.7.jar:na]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-2.1.7.jar:na]
Caused by: java.lang.NullPointerException: null
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:165) ~[quartz-2.1.7.jar:na]
    ... 6 common frames omitted

数据源配置:

<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
    destroy-method="close">
    <property name="driverClass" value="${batch.jdbc.driver}" />
    <property name="jdbcUrl" value="${batch.jdbc.url}" />
    <property name="username" value="${batch.jdbc.user}" />
    <property name="password" value="${batch.jdbc.password}" />
    <property name="idleConnectionTestPeriod" value="60" />
    <property name="idleMaxAge" value="240" />
    <property name="maxConnectionsPerPartition" value="${batch.jdbc.pool.size}" />
    <property name="minConnectionsPerPartition" value="4" />
    <property name="partitionCount" value="1" />
    <property name="acquireIncrement" value="3" />
    <property name="statementsCacheSize" value="0" />
    <property name="releaseHelperThreads" value="3" />
</bean>

石英的配置:

<property name="quartzProperties">
            <props>
                    <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
                    <!-- <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop> -->
                    <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                    <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
                    </prop>
                    <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
                    <prop key="org.quartz.jobStore.isClustered">true</prop>
                    <prop key="org.quartz.scheduler.instanceName">MyClusteredScheduler</prop>
                    <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            </props>
</property>

我的理解是在关闭时, dataSource 被破坏并且 logger 变为 null ,导致 NullPointerException。无法确定原因,请指出正确的方向。

4

1 回答 1

0

我没有尝试过使用弹簧石英。但是,通常在使用石英时,我们会优雅地关闭石英。优雅地说,我的意思是我将仅在执行所有待处理的作业(当前执行但尚未标记完成的作业)后关闭调度程序。

对于优雅关闭,我们在使用方法关闭时传递属性 true。在此处参考 API

我很想知道 spring 石英实现是如何做到这一点的。

于 2013-06-19T09:54:05.440 回答