Question

I defined a bean called A in spring configuration and A used spring's transaction.Obviously,when I use A's methods,we are in the transaction. But if A is a thread,what will happen when A start(),is it still in transaction and is it the same condition as before?

Was it helpful?

Solution

If A extends Thread, and A's start() method is transactional, then Spring will do as for all the other transactional methods: a transaction will start (if not already started) when start() is called, and the transaction will end as soone as start() returns (if it began when start() was called).

The run() method of A will be executed in another thread, outside of any Spring transaction. If this run() method calls a transactional method of another, injected, Spring component, then this method will be executed inside a Spring transaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top