There is a method commit in user transaction class. When we do commit on it, first it finds that if there is a transaction associated with this thread. My question is how at core java level we can find out if there is a transaction associated with current thread?
(i know its a internal process to JTA apis but still interested )
There is a method commit in user transaction class. When we do commit on
Share
One simple way I can think of is to keep a map with Thread reference as ‘key’ and the Transaction object as ‘value’. For a thread with no transaction created in the past, there will be no such key in the map and hence UserTransaction implementation can decide to throw an exception.
Any line of code can know which Thread it is by Thread.currentThread().
Hope that helps.
Thanks,
Nitin