Extending semaphore permissions in Java

Is it possible to add semaphore permission in Java?

Semaphore s = new Semaphore(3); 

After that, somewhere in the code I want to change the permissions to 4. Is this possible?

+6
source share
1 answer

Yes. The release method (vaguely named imo) can be used to increase permissions since from the docs:

 There is no requirement that a thread that releases a permit must have acquired that permit by calling acquire. Correct usage of a semaphore is established by programming convention in the application. 

In other words:

 semaphore.release(10); 

10 more permissions will be added if the call to threads is not received.

+10
source

Source: https://habr.com/ru/post/911208/


All Articles