Semaphore (信号量)

    xiaoxiao2026-05-12  2

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

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

    构造函数,指定许可证的数量。代表共享资源的个数。可以设为0.也可以设为负数。 void java.util.concurrent.Semaphore. acquire() throws InterruptedException

    从信号量中获得一个许可证。若得不到会被阻塞,直到有一个许可证可用。

    void java.util.concurrent.Semaphore. release() 释放一个许可证,还给信号量。
    最新回复(0)