Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Launching multi-threaded job by JMS

  1. #11
    Join Date
    Apr 2008
    Posts
    14

    Default

    Hi lucasward. You are right, the pointcut / tx attrs config I post was different from Dave post, I am sorry about that, that's my fault.

    Due to I used 1.0.0. rc1(I mentioned it the first time I post this topic), then the old config might fit for the rc1 framwork(like the package structure, classes' and methods' name).

    Now I have double checked that pointcut / tx attrs config in version 1.0.0 Final, it is the most updated just like 1.0.1.dev-SNAPSHOT and Dave post before.

    I had done according to what Dave said.
    Anyway, I have
    a) upgraded to version 1.0.0 final.
    b) compared pointcut / tx attrs config with 1.0.1.dev-SNAPSHOT and your post.
    c) run the test case from a unit test. (As I said before, running the samples test case from unit test is ok, but when running the multi-threaded job(inner transaction) within outer transaction, it fails, still the same exception.)
    So, would anyone tell me why?

  2. #12
    Join Date
    Apr 2008
    Posts
    14

    Default

    Please note that I could run other single threaded jobs by MDB.

  3. #13
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Can you post the stack trace from your unit test?

  4. #14
    Join Date
    Apr 2008
    Posts
    14

    Default

    Dave, I'm using 1.0.0.FINAL, the stack trace is:
    Code:
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R org.springframework.batch.core.UnexpectedJobExecutionException: Encountered an error saving batch meta data.
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.step.item.ItemOrientedStep.execute(ItemOrientedStep.java:410)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at $Proxy39.execute(Unknown Source)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:125)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:86)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:81)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.test.batch.sample.JobLauncherService.launchJob(JobLauncherService.java:53)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.test.rtp.batch.mdb.listener.SpringBatchMDBListener.processMessage(SpringBatchMDBListener.java:63)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.abc.esf.jms.async.templates.EsMessageListener.onMessage(EsMessageListener.java:96)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.abc.esf.jms.async.impl.EsMessageDrivenBean.onMessage(EsMessageDrivenBean.java:107)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper$PriviledgedOnMessage.run(MDBWrapper.java:302)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper.callOnMessage(MDBWrapper.java:271)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper.onMessage(MDBWrapper.java:240)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.mq.jms.MQSession.run(MQSession.java:1592)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.JMSSessionHandle.run(JMSSessionHandle.java:970)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.connectionConsumerOnMessage(ServerSession.java:891)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.onMessage(ServerSession.java:656)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.dispatch(ServerSession.java:623)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:37)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:96)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:132)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java:481)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R Caused by: org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
    	at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
    	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:719)
    	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
    	at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:756)
    	at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:327)
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdate(SimpleJobRepository.java:238)
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdateExecutionContext(SimpleJobRepository.java:247)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:615)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy37.saveOrUpdateExecutionContext(Unknown Source)
    	at org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:312)
    	at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:215)
    	at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
    	at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1114)
    	at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:195)
    	at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:187)
    	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)

  5. #15
    Join Date
    Apr 2008
    Posts
    14

    Default

    stack trace (Cont'd)

    Code:
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:719)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:756)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:327)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdate(SimpleJobRepository.java:238)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdateExecutionContext(SimpleJobRepository.java:247)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at $Proxy37.saveOrUpdateExecutionContext(Unknown Source)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:312)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:215)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1114)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:195)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:187)
    [4/28/08 9:36:33:923 CST] 0000001d SystemErr     R 	... 1 more

  6. #16
    Join Date
    Apr 2008
    Posts
    14

    Default

    My configuration:

    data-source-context.xml
    Code:
    	......
    	<bean id="wasTransactionManager" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean" />
                   
    	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">       
    		<property name="transactionManager" ref="wasTransactionManager" />
    		<property name="allowCustomIsolationLevels" value="true" />
    	</bean>
    	......
    simple-job-launcher-context.xml
    Code:
    	......
    	<aop:config>
    		<aop:advisor pointcut="execution(* org.springframework.batch.core..*Repository+.*(..))"
    			advice-ref="txAdvice" />
    	</aop:config>
    
    	<tx:advice id="txAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="create*" propagation="REQUIRES_NEW" isolation="SERIALIZABLE" />
    			<tx:method name="*" />
    		</tx:attributes>
    	</tx:advice>
    	......

  7. #17
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Quote Originally Posted by charmchuan View Post
    running the multi-threaded job (inner transaction) within outer transaction
    Can you elaborate on that a bit? It sounds fishy, but I don't really know what you mean. I don't see the "outer transaction" in your configuration below (or in the stack trace). What do you mean by that exactly?

    Can you run a unit test just from com.test.batch.sample.JobLauncherService.launchJob and check that it works from there on down? (Ditch the MDB, as I suggested originally.)

  8. #18
    Join Date
    Apr 2008
    Posts
    14

    Default

    What I mean 'outer transaction' is the J2EE container's transaction(UserTransaction), the following code will cause the same exception above, I am not using MDB in the following scenario:
    Quote Originally Posted by charmchuan View Post
    Also, I tried to retrieve the container's Transaction directly from the Web:
    Code:
        public void testMultiTreadsParallelJob() throws Exception{
            Context initContext = new InitialContext();
            UserTransaction tran = (UserTransaction) initContext.lookup("java:comp/UserTransaction");
    
            tran.begin();
            
            // Launch the multi-threaded job.
    
            tran.commit();
        }
    Then it threw the same exception too.

    So, my conclusion is : The transaction belongs to multi-threaded job can't be embedded in the application server's transaction. But why? Is there any conflict with application server's transaction.

  9. #19
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    There certainly is a conflict and the error is easy to understand now. The outer transaction hasn't committed yet when the first step processing thread starts and tries to update the StepExecution.

    Your outer transaction will not commit until after the whole job is complete. This is unnecessary, and kind of an abuse of the UserTransaction - it could be held open for many hours. If you need a transaction for your trigger message you would be better off launching the job in a new thread (using a threaded task executor for the job launcher as well as the step), then the launcher will return immediately with an incomplete JobExecution and the transaction can commit and acknowledge the message back to the caller.

  10. #20
    Join Date
    Apr 2008
    Posts
    14

    Default

    Two points I don't understand:

    1. When I set propagation="REQUIRES_NEW", doesn't it mean that batch job will create its own transaction for managing itself and BATCH_% tables' data update?
    What my understanding is that it is seperated from outer transaction(UserTransaction). It suspends the outer transaction till it ends, manages its own transaction which is independent of the outer transaction no matter outer transaction commit() or rollback(), persists update of StepExecution without impact of outer transaction(e.g. outer rollback). Maybe what I think is not right, please correct me if so.

    2. It is strange that I could run the single threaded job in this scenario:
    Code:
        public void test() throws Exception{
            Context initContext = new InitialContext();
            UserTransaction tran = (UserTransaction) initContext.lookup("java:comp/UserTransaction");
    
            tran.begin();
            
            // Launch the single threaded job.
    
            tran.commit();
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •