S
S
synapse_people2018-08-18 09:27:43
Java
synapse_people, 2018-08-18 09:27:43

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

1 answer(s)
S
Sergey Gornostaev, 2018-08-18
@sergey-gornostaev

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 question

Ask a Question

731 491 924 answers to any question