📄 barrier.java
字号:
package org.antlr.misc;/**A very simple barrier wait. Once a thread has requested a * wait on the barrier with waitForRelease, it cannot fool the * barrier into releasing by "hitting" the barrier multiple times-- * the thread is blocked on the wait(). */public class Barrier { protected int threshold; protected int count = 0; public Barrier(int t) { threshold = t; } public synchronized void waitForRelease() throws InterruptedException { count++; // The final thread to reach barrier resets barrier and // releases all threads if ( count==threshold ) { // notify blocked threads that threshold has been reached action(); // perform the requested operation notifyAll(); } else while ( count<threshold ) { wait(); } } /** What to do when everyone reaches barrier */ public void action() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -