Answer the question
In order to leave comments, you need to log in
Hierarchical locking and Executors in Java?
There is a task queue that is launched by the ThreadPoolExecutor. There was a need to add a hierarchical lock.
Suppose we have tasks in the queue that make calculations at different business logic data levels. A -> B -> C. I.e. if a task is running with data A, then, automatically, B and C are pending. Similarly, as it is implemented in the DBMS through the Multi-Granular Lock mechanism: files -> pages -> records.
1) Are there any Java libraries that allow you to do hierarchical locking?
2) For a large queue, it would be impractical to spawn threads and block them using system locks. Is there any solution to describe the dependency of executable tasks, store them in a queue like in an Executor, and call them only when the dependent tasks have completed their work?
At the moment, I could find only a few articles with the theory on the net, perhaps someone has already solved a similar problem.
Answer the question
In order to leave comments, you need to log in
I see the dependency of tasks on each other (through data). Suppose that after completing its work, task A starts tasks B and C and no locks.
Or you can have some data storage and some set of handlers that act on the data, for example:
One handler takes objects of the Order type whose NEW state puts them in the CHECKED or FRAUD state according to some logic of their own.
Another handler takes an Order in the CHECKED state, conducts a transaction and puts PAID or NOT_PAID. Etc.
Architectural pattern Blackboard_system.
I would recommend Akka.io.
EventA -> HandlerA -> EventB -> HandlerB
For each handler, you can separately configure the basket and the number of threads. It is possible to organize event routers, akka.io/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question