문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top