It's hard to guess what exactly is happening in your code, however these are possible problems:
DB level lock. This can happen if you update the same DB object in doWork1() and doWork2() . Since both methods execute in a single transaction, updates made inside doWork1() will not be executed until doWork2() . Both methods may try to lock the same database object and wait for it. Technically, this can be any DB object: a row in a table, an index, an entire table, etc.
Analyze your code and try to find what you can block. You can also view the database transaction log while the method is running. All popular databases provide functionality that helps find problem areas.
Slow down during Hibernate context update. If you update too many objects, the ORM engine (say, Hibernate) should flood them and store them in memory. Literally, Hibernate should have all the old states and all new states of the updated objects. Sometimes this makes it completely non-optimal.
You can specify this using debugging. Try to find the slowest place and check what exactly is called there. I can guess that it slows down when hibernate updates the state of the cache.
One more problem. I see that you create MyServiceImpl using the constructor during processStage() . I recommend that you replace this code with spring autowiring. First of all, how you use it is not the way it was intended to be used, but theoretically it can also affect execution.
I will get a self-starting problem, what is impractical in a transaction?
No, it will work just fine, ignoring all annotations. The calls to doChildWork() and doChildWork2() inside doWork2() will be treated as standard java calls (spring cannot add any magic to them if you call them directly).
source share