This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Launching multi-threaded job by JMS

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:

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:

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:

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

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

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.)

Comment

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

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.)