Batch procedure (with BTM) works only once per server restart.
raffaele.camanzo Sep 2, 2009 4:44 PMHi all,
I made a batch procedure to manipulate a large amount of data but I'm facing a strange behaviour.
Environment:
- AS: jBoss 4.2.3.GA
- SEAM: latest (2.2.0.GA, also tried with 2.0.1, 2.1.2)
- QUARTZ: latest (1.6.5 also tried with 1.6.1)
- HIBERNATE: latest (3.3.2)
The logic behind the procedure is quite simple: I have to execute a doSomething() operation on a huge amount of data, moreover doSomething() executes complex evaluations involving other data; CMT causes a transaction timeout exception then I decided to use BMT in order to split my batch over many transactions.
Here's the scheduler method:
@Asynchronous public QuartzTriggerHandle schedule(@Expiration Date when, @IntervalDuration Long interval) throws Exception { batchManager.doTheJob(); return null; }
The batchManager is the stateless bean I use to do the job:
@Stateless @Name("batchManager") @TransactionManagement(TransactionManagementType.BEAN) @AutoCreate public class BatchManager implements BatchManagerInterface { private static final long serialVersionUID = 521276102521455864L; private static final int BATCH_SIZE = 100; @In private EntityManager entityManager; @Resource private UserTransaction userTransaction; ... public void doTheJob() throws Exception { userTransaction.begin(); entityManager.joinTransaction(); List<Debitore> debitori = new ArrayList<Debitore>(); debitori.addAll(caricaDebitori(cliente)); userTransaction.commit(); int size = debitori.size(); int index = 0; if(debitori.size() > 0) { while((index < size)) { try { userTransaction.begin(); entityManager.joinTransaction(); int intsize = index + BATCH_SIZE > size ? size : index + BATCH_SIZE; for(; index < intsize; index++) { Debitore d = debitori.get(index); doAllTheStuff(d); } userTransaction.commit(); } catch(Exception e) { e.printStackTrace(); userTransaction.rollback(); } } } } }
When I start the timer for the first time everything is ok, the Quartz scheduler starts the job and it completes successfully. After the IntervalDuration Quartz executes again the job but I get this exception:
2009-09-02 16:39:50,081 DEBUG [it.finservice.odino.core.OLog] |WS-or-TIMER| [StatisticheOperativeManager.aggiornaDati] Stato della sessione. connesso: TRUE - aperto: TRUE - sp orco: FALSE 2009-09-02 16:39:50,082 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed! 2009-09-02 16:39:50,083 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76) 2009-09-02 16:39:50,083 ERROR [STDERR] at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheOperativeManager.caricaClienti(StatisticheOperativeManager.java:1 08) 2009-09-02 16:39:50,083 ERROR [STDERR] at it.finservice.odino.scheduler.statisticheOperative.bean.StatisticheOperativeManager.aggiornaDati(StatisticheOperativeManager.java:82 ) 2009-09-02 16:39:50,083 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2009-09-02 16:39:50,083 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2009-09-02 16:39:50,083 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 2009-09-02 16:39:50,083 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50) 2009-09-02 16:39:50,083 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor448.invoke(Unknown Source) 2009-09-02 16:39:50,083 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 2009-09-02 16:39:50,083 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 2009-09-02 16:39:50,083 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.tx.BMTInterceptor.handleStateless(BMTInterceptor.java:71) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.tx.BMTInterceptor.invoke(BMTInterceptor.java:131) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81) 2009-09-02 16:39:50,084 ERROR [STDERR] at $Proxy777.aggiornaDati(Unknown Source) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 2009-09-02 16:39:50,084 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.javassist.tmp.java.lang.Object_$$_javassist_seam_7.aggiornaDati(Object_$$_javassist_seam_7.java) 2009-09-02 16:39:50,084 ERROR [STDERR] at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler.schedule(StatisticheOperativeScheduler.java:74) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2009-09-02 16:39:50,084 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 2009-09-02 16:39:50,084 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,084 ERROR [STDERR] at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) 2009-09-02 16:39:50,085 ERROR [STDERR] at it.finservice.odino.scheduler.statisticheOperative.StatisticheOperativeScheduler_$$_javassist_seam_6.schedule(StatisticheOperativeSc heduler_$$_javassist_seam_6.java) 2009-09-02 16:39:50,085 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2009-09-02 16:39:50,085 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2009-09-02 16:39:50,085 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 2009-09-02 16:39:50,085 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.quartz.core.JobRunShell.run(JobRunShell.java:202) 2009-09-02 16:39:50,085 ERROR [STDERR] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) 2009-09-02 16:39:50,086 ERROR [STDERR] Caused by: org.hibernate.SessionException: Session is closed! 2009-09-02 16:39:50,086 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) 2009-09-02 16:39:50,087 ERROR [STDERR] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1138) 2009-09-02 16:39:50,087 ERROR [STDERR] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) 2009-09-02 16:39:50,087 ERROR [STDERR] at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67) 2009-09-02 16:39:50,087 ERROR [STDERR] ... 93 more
I checked the session state when the exception occurs and:
Session is connected, open and not dirty.
The only way to execute it successfully again is restarting the AS.
Any help is really appreciated.
Regards,
Raffaele Camanzo