Reputation: 67
I am a new bird in spring so your help will be really helpful for me.
Suppose I have the following scenario:
@Transactional(propagation = Propagation.REQUIRED, timeout = 1, isolation = Isolation.READ_COMMITTED,rollbackFor=Exception.class)
public boolean bookMovieTicket()
{
//Check how many tickets are available
int noTicket=getAvailableTicket();
if(noTicket>0)
{
//decrements the count of ticket
noTicket--;
updateCount(noTicket);
return true;
}
else
{
return false;
}
}
Now Suppose two user hit my application so as my understanding for both the request servlet would create the new thread which has their own stack of local variable.When thread A would hit the function bookTicket() it will start the transaction if there is no transaction exist,Now my question is when thread B will invoke this method would Thread B will join the existing transaction or would it create the new one.
This question could be silly but please clear this doubt that for each web request there would be a new transaction created by the transaction manager? and for specific to that request(life cycle of that request) propagation behaviour of transaction applied?
I would like to know, for each web request is spring transactional manager start a new Transaction thread,I am asking this because in servlet.xml we usually configured the transaction manager bean as singleton by default
Upvotes: 0
Views: 52
Reputation: 2542
Transactional is only for data bases, it will not roll back altered fields. If you alter a field in your class, you need to deal with concurrency, e.g. make the count variable an AtomicInteger.
Upvotes: 1