我有一个java模块,它需要通过接口(interface)同时执行一组任务(为实现该模块的框架提供低级控制和处理),但同时不能太多,java.util。并发.Semaphore
似乎非常适合这个。
我不确定的一个问题是 release()
和 acquire()
调用的线程安全性。是否可以一个线程获取信号量锁,然后另一个线程释放它?
最佳答案
这是 Javadoc about release()
上的注释
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.
所以是的。你可以的。
关于java - 您可以在您执行 acquire() 的不同线程上调用 java.util.concurrent.Semaphore.release() 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50328898/