Announcement Announcement Module
Collapse
No announcement yet.
Synchronization and Transaction Issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.
Working...
X