Remember the pit that the spring thread calls the transaction without rolling back

A requirement, originally planned to use multi-threading to insert multiple libraries separately, buried int a=1/0 to test the rollback, and found that there was no rollback

If you want to manually control the submission of transactions, you have to start multiple transactions yourself, manually write sql, manually submit and rollback, and the cost is relatively high. What's the best way?

Later, it was changed to a single-threaded call to the @Transactional method of the service, but the result was that the pit was not rolled back

Reason: The thread calls the method of its own class, and does not use the proxy class of spring aop, so it just executes an ordinary method.

Solution: Inject a service with @Resource, and then use the thread to call the service method, so that's it

 

Supongo que te gusta

Origin blog.csdn.net/babing18258840900/article/details/105120935
Recomendado
Clasificación