Announcement Announcement Module
Collapse
No announcement yet.
Launching multi-threaded job by JMS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Launching multi-threaded job by JMS

    Hi All,

    I have encountered a problem when launching a multi-threaded job triggered by JMS.

    Here is my scenario:

    Client pushes message in the queue, MDB listens to the queue and picks up the message, then MDB launch a multi-threaded job.

    When Job had been started and the first time Step(the first thread finished the Tasklet) committed the changes in table BATCH_STEP_EXECUTION according to ‘commitIntervel’ property of Step, it threw the following exception:

    Code:
    SystemErr     R org.springframework.batch.core.UnexpectedJobExecutionException: Encountered an error saving batch meta data.
    SystemErr     R 	at org.springframework..batch.core.step.item.ItemOrientedStep.execute(ItemOrientedStep.java:415)
    SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
    SystemErr     R 	at org.springframework..aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
    SystemErr     R 	at org.springframework..aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
    ...
    SystemErr     R 	at org.springframework..aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    SystemErr     R 	at $Proxy9.execute(Unknown Source)
    SystemErr     R 	at org.springframework..batch.core.job.SimpleJob.execute(SimpleJob.java:121)
    SystemErr     R 	at org.springframework..batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:90)
    SystemErr     R 	at org.springframework..core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
    SystemErr     R 	at org.springframework..batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:85)
    SystemErr     R 	at com.test.batch.sample.JobLauncherService.launchJob(JobLauncherService.java:54)
    ...
    SystemErr     R 	at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:132)
    SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java:481)
    SystemErr     R 	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
    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:668)
    	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:678)
    	at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:705)
    	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 org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:315)
    	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)
    
    SystemErr     R 	at org.springframework..dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
    SystemErr     R 	at org.springframework..jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:668)
    SystemErr     R 	at org.springframework..jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:678)
    SystemErr     R 	at org.springframework..jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:705)
    SystemErr     R 	at org.springframework..batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:327)
    SystemErr     R 	at org.springframework..batch.core.repository.support.SimpleJobRepository.saveOrUpdate(SimpleJobRepository.java:238)
    SystemErr     R 	at org.springframework..batch.core.repository.support.SimpleJobRepository.saveOrUpdateExecutionContext(SimpleJobRepository.java:247)
    SystemErr     R 	at org.springframework..batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:315)
    SystemErr     R 	at org.springframework..batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:215)
    SystemErr     R 	at org.springframework..scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
    SystemErr     R 	at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1114)
    SystemErr     R 	at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:195)
    SystemErr     R 	at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:187)
    SystemErr     R 	... 1 more
    Then I debugged and went into the snippet code:

    org.springframework.batch.core.repository.support. SimpleJobRepository
    Code:
    public void saveOrUpdate(StepExecution stepExecution) {
    	...
    	if (stepExecution.getId() == null) {
    		stepExecutionDao.saveStepExecution(stepExecution);
    		}
    	else {
    		// existing execution, update
    		stepExecutionDao.updateStepExecution(stepExecution);
    	}
    }
    It is correct that stepExecution.getId() is not null after the first time executing stepExecutionDao.saveStepExecution(stepExecution); , but its corresponding record is not found in table BATCH_STEP_EXECUTION, so that count is 0 below and it fails when executing the follow snnipet:

    org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao
    Code:
    public void updateStepExecution(StepExecution stepExecution) {
    	...
    		int count = getJdbcTemplate().update(
    					getQuery(UPDATE_STEP_EXECUTION),
    					parameters,
    					new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
    							Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER });
    
    			// Avoid concurrent modifications...
    			if (count == 0) {
    				int curentVersion = getJdbcTemplate().queryForInt(
    						getQuery(CURRENT_VERSION_STEP_EXECUTION),
    						new Object[] { stepExecution.getId() });
    				throw new OptimisticLockingFailureException("Attempt to update step execution id="
    						+ stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + "), where current version is "+curentVersion);
    			}
    
    			stepExecution.incrementVersion();
    	...
    }
    It appears that there is transaction matter, which leads not commit on DB level.

    Here’s my environment:

    Spring Batch 1.0.0.rc1
    WebSphere Application Server 6.1.0.11
    Oracle 10g
    MQ 6.0
    DB and MDB’s XA resources ablility are enabled, also configured on WAS 6.1
    I used ‘JtaTransactionManager’ as my transaction manager, and ‘WorkManagerTaskExecutor’ as TaskManager for thread pools management.

    Could anyone give me a solution? Thank you!

    BTW, the 2 scenarios I have tried below are OK:
    JMS trigger single-threaded job. (JMS resource + JDBC resource)
    Multi-threaded job run on web container. (JDBC resource)

  • #2
    Which transaction manager are you using? Does the multi-threaded job work from the command line?

    From the stack trace I think I can tell what the problem is: you haven't got a transaction in your JobRepository method execution. Did you read the section of the user guide on declaring transactions for the repository? The samples have a tx:advice and a pointcut that you can just re-use:


    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>
    Last edited by Dave Syer; Apr 19th, 2008, 04:44 AM. Reason: spelling

    Comment


    • #3
      Hi Dave,

      Which transaction manager are you using?
      I am using org.springframework.transaction.jta.JtaTransaction Manager.


      Does the multi-threaded job work from the command line?
      I get the JobLauncher and Job from application context, then launch my multi-threaded job in method onMessage() of MDB class.


      Did you read the section of the user guide on declaring transactions for the repository? The samples have a tx:advice and a pointcut that you can just re-use:
      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>
      Yes! And I have never changed this configuration, It is the same as yours.


      Here is my scenario:

      Client pushes message in the queue, MDB listens to the queue and picks up the message, then MDB launch a multi-threaded job.
      What I don't understand is why I can launch the non multi-threaded job(not configure TaskExecutor in Job Bean)nomally in this way. Surely, my ItemReader reads items from DB table so that task can be run on multi-threaded mode.

      I am not sure whether there is one transaction per thread, or one transaction shared by multiple threads? And why the new transaction for repository embedded in the existed trasaction can't be commit?

      Also, I can launch multi-threaded job in the way of web container(I used J2EEUnit).

      Comment


      • #4
        Originally posted by charmchuan View Post
        I get the JobLauncher and Job from application context, then launch my multi-threaded job in method onMessage() of MDB class.
        What I asked was "can you run it from the command line"? If you do that you may find it easier to test, and the issue is unlikely to be anything to do with the MDB.

        Yes! And I have never changed this configuration, It is the same as yours.
        I can't see the TX advice in your stack trace, so you must be doing something wrong here. Is spring-aop on your classpath?

        Comment


        • #5
          Due to forum's restriction of text characters size, sorry that I cut off some trace before.

          Here is the full stack trace:
          Code:
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R org.springframework.batch.core.UnexpectedJobExecutionException: Encountered an error saving batch meta data.
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.step.item.ItemOrientedStep.execute(ItemOrientedStep.java:415)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:42)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at $Proxy9.execute(Unknown Source)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:121)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:90)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:85)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.test.batch.sample.JobLauncherService.launchJob(JobLauncherService.java:54)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.test.batch.mdb.listener.SpringBatchMDBListener.processMessage(SpringBatchMDBListener.java:63)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.abc.jms.async.templates.MyMessageListener.onMessage(MyMessageListener.java:96)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.abc.jms.async.impl.MyMessageDrivenBean.onMessage(MyMessageDrivenBean.java:107)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper$PriviledgedOnMessage.run(MDBWrapper.java:302)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper.callOnMessage(MDBWrapper.java:271)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.MDBWrapper.onMessage(MDBWrapper.java:240)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.mq.jms.MQSession.run(MQSession.java:1592)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.JMSSessionHandle.run(JMSSessionHandle.java:970)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.connectionConsumerOnMessage(ServerSession.java:891)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.onMessage(ServerSession.java:656)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.dispatch(ServerSession.java:623)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at java.lang.reflect.Method.invoke(Method.java:615)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:37)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:96)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:132)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java:481)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
          [4/18/08 18:14:58:876 CST] 0000001b 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:668)
          	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:678)
          	at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:705)
          	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 org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:315)
          	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)
          
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.dao.support.DataAccessUtils.requiredSingleResult(DataAccessUtils.java:71)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:668)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:678)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:705)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:327)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdate(SimpleJobRepository.java:238)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.repository.support.SimpleJobRepository.saveOrUpdateExecutionContext(SimpleJobRepository.java:247)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.core.step.item.ItemOrientedStep$1.doInIteration(ItemOrientedStep.java:315)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:215)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1114)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ws.asynchbeans.WorkWithExecutionContextImpl.go(WorkWithExecutionContextImpl.java:195)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	at com.ibm.ws.asynchbeans.CJWorkItemImpl.run(CJWorkItemImpl.java:187)
          [4/18/08 18:14:58:876 CST] 0000001b SystemErr     R 	... 1 more
          Last edited by charmchuan; Apr 21st, 2008, 03:33 AM.

          Comment


          • #6
            And here is my configuration of tx:advice and pointcut:
            Code:
            	<aop:config>
            		<aop:advisor pointcut="execution(* org.springframework.batch.execution..*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="*Create*" propagation="REQUIRED" isolation="SERIALIZABLE" /> -->
            			<tx:method name="*" />
            		</tx:attributes>
            	</tx:advice>
            I can run ParallelJobFunctionalTests sample normally, also other samples in package, so I think the configuration of tx:advice and pointcut is ok.

            Comment


            • #7
              I have tried to set my MDB's transaction attribute to 'NotSupported', then it works normally, whereas, 'Required' will threw the above exception.
              Code:
              	<assembly-descriptor>
              		<container-transaction>
              			<method>
              				<ejb-name>TestSpringBatchMDB</ejb-name>
              				<method-name>onMessage</method-name>
              				<method-params>
              					<method-param>javax.jms.Message</method-param>
              				</method-params>
              			</method>
              			<trans-attribute>NotSupported</trans-attribute>
              		</container-transaction>
              	</assembly-descriptor>
              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 either.

              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.

              Comment


              • #8
                Originally posted by charmchuan View Post
                And here is my configuration of tx:advice and pointcut.
                What version of Spring Batch are you using? That's actually an old pointcut / tx attrs config from a previous version, which is definitely a problem if you are using 1.0.0. Can you a) upgrade to 1.0.0 if you haven't already (or 1.0.1.dev-SNAPSHOT), b) carefully copy the tx configuration from my post or from the samples, c) try running on the command line / from a unit test?

                Comment


                • #9
                  Dave, I used Spring Batch 1.0.0.rc1, and I never changed the pointcut / tx attrs config (which I have compared with was indeed the same as 1.0.1.dev-SNAPSHOT).

                  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.)
                  Last edited by charmchuan; Apr 23rd, 2008, 04:12 AM.

                  Comment


                  • #10
                    It's definitely not the same pointcut. If you look at it, it's batch.execution, instead of batch.core. Further, the advice should be on *create not *Create. It's a subtle difference, but it will affect whether it's actually being applied.

                    Comment


                    • #11
                      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?

                      Comment


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

                        Comment


                        • #13
                          Can you post the stack trace from your unit test?

                          Comment


                          • #14
                            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)

                            Comment


                            • #15
                              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

                              Comment

                              Working...
                              X