Semaphore (信号量)

我觉得它比synchornized()好用多啦。


java.util.concurrent.Semaphore.Semaphore(int permits)

构造函数,指定许可证的数量。代表共享资源的个数。可以设为0.
Creates a Semaphore with the given number of permits and nonfair fairness setting.

void java.util.concurrent.Semaphore. acquire() throws InterruptedException
从信号量中获得一个许可证。若得不到会被阻塞,直到有一个许可证可用。

Acquires a permit from this semaphore, blocking until one is available, or the thread is interrupted. 


void java.util.concurrent.Semaphore. release()
释放一个许可证,还给信号量。
Releases a permit, returning it to the semaphore. 

你可能感兴趣的:(Semaphore (信号量))