Answer the question
In order to leave comments, you need to log in
How to implement a lock on several objects at once?
There are many instances of the same class, which in fact just serves as a container for components.
those. the IEntity class with the getComp(...) method, on which all sorts of POJOs are located.
The task is to implement such a lock so that you can simultaneously get a lock on 2 or more such objects ...
That is, for example, the ILock class is added with the addEntity(IEntity ent), lock/unlock methods.
Further, it is used as follows: first, objects are added on which it is necessary to simultaneously obtain a lock and the lock method is called. At the same time, if a lock on at least 1 object has already been captured, then a new lock must wait until it is released.
What ideas?
Answer the question
In order to leave comments, you need to log in
You create java.util.concurrent.locks.Lock , pass it to the constructor of the objects you want to lock, and try to capture it in the methods of the objects.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question