-
Mar 2nd, 2012, 03:41 PM
#1
Synchronization and Transaction Issue
We have a service layer which brings in documents into the system, which are then added to a batch. Below is skeletal of the two methods.
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class})
public void bringDocument(){
//bring in documents
//add document to batch
createBatch();
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = { RuntimeException.class})
public synchronized createBatch(){
}
Case I:
If I have both my methods declared in the same spring beans I get exceptions during the batch process since we create batch with unique names. I found that the REQUIRES_NEW does not come into play at all so that was the problem here.
Case II:
If I remove the @Transactional from bringDocuments it works fine. But why?
Case III:
If I move createBatch to a separate class, which is a spring bean, if I invoke it as
sycnhronized(this){
BatchUtils.createBatch();
}
it will work. And I keep the @Transactional attribute on the bringDocuments method.
Why do I need to have a synchronized(this) block? Also how does spring work with sychronized beans? When does it truly commit a transaction.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules