Is it possible to use a transaction in another thread?
Like pass a transaction created in thread A and then execute some logic in Thread B within the same transaction?
I have two queues and separate executors which handles population of certain Entity types.
However, a batch job is managing both population and waiting for each to finish. It would be unnecessary to create two transactions. If one fails, ideally I'd want all data to be rolled back so it would have been ideal to run them as one transaction as well as it provides improved performance.
So, is it possible to create one transaction, pass it along to another thread, execute some stuff within the boundaries of the first one?
I am using Spring and Hibernate and currently using
TransactionTemplate template = new TransactionTemplate( getTransactionManager() );
template.setPropagationBehavior(propagationBehavior);
template.setReadOnly(readOnly);
TransactionStatus status = getTransactionManager().getTransaction(template);
to create a transaction, not using annotations at all and have no plans to do so either.