📄 semaphore.java
字号:
/* * Semaphore.java * * Created on February 16, 2004, 1:54 PM */package jcdwriter.model;/** * * @author rmallappa */public class Semaphore { int excessSignals = 0; /** Creates a new instance of Semaphore */ public Semaphore() { } public synchronized void waitForSignal() { try { if (excessSignals > 0) {// System.out.println("Got signal without wait! Cool!"); } else {// System.out.println("Waiting."); wait(); } } catch (InterruptedException e) { } excessSignals = excessSignals - 1; notifyAll(); return; } public synchronized void signal() { excessSignals = excessSignals + 1;// System.out.println("Gog a signal."); notifyAll(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -