Kil*_*Ors 10 java concurrency multithreading semaphore
我可以在Java中为信号量添加更多许可吗?
Semaphore s = new Semaphore(3);
Run Code Online (Sandbox Code Playgroud)
在代码中的某个地方之后,我想将许可证更改为4.这可能吗?
Jim*_*Jim 15
是.该释放方法(IMO混淆的命名)可用于递增许可以来,从文档:
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.
Run Code Online (Sandbox Code Playgroud)
换一种说法:
semaphore.release(10);
Run Code Online (Sandbox Code Playgroud)
如果线程调用没有获得任何许可,将增加10个许可.