2013-06-19 137 views
2

我正在使用Spring Batch和quartz。我有一個bean銷燬方法,它在tomcat關閉時重置數據庫中的一些標誌。由於以下異常destroy方法不叫:當tomcat關閉時在Spring批處理中獲取NullPointerException

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> 

我明白了什麼是停機時,數據源被破壞,並且記錄器變爲空,導致NullPointerException。無法確定原因,請指向正確的方向。

回答

0

我還沒有試過用彈簧石英。但是,通常在使用Quartz時,我們優雅地關閉 石英。通過優雅的方式,我的意思是,在執行所有待執行的作業(當前正在執行的作業,但尚未標記爲 的作業)後,我將關閉調度程序 。

爲了正常關閉,我們在使用方法關閉時傳遞屬性true。 參考API here

我很想知道春季石英實現如何做到這一點。

+0

我已添加此屬性以等待作業完成:'code' true'code'。而且我現在沒有得到任何異常,但我的bean銷燬方法仍然沒有被調用?另外,我正在使用_italic_註冊JDBC驅動程序[org.postgresql.Driver],但在Web應用程序停止時未能註銷它。爲了防止內存泄漏,JDBC驅動程序已被強制註銷。 _italic_。請注意,我使用boncep而不是dbcp進行連接池,希望不應該得到這個錯誤? – Prashant

+0

另外,我在3.2.3版本中使用了quartz 2.1.7,其中主線程連接所有其他調度程序線程來完成。我的bean銷燬方法仍然沒有被調用。 – Prashant

+0

爲此歡呼三聲!!!!! :-)。 – Shinchan

相關問題