Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 13 14 package javax.concurrent; 15 16 46 47 public class Latch implements Sync { 48 protected boolean latched_ = false; 49 50 59 60 public void acquire() throws InterruptedException { 61 if (Thread.interrupted()) throw new InterruptedException (); 62 synchronized(this) { 63 while (!latched_) 64 wait(); 65 } 66 } 67 68 public boolean attempt(long msecs) throws InterruptedException { 69 if (Thread.interrupted()) throw new InterruptedException (); 70 synchronized(this) { 71 if (latched_) 72 return true; 73 else if (msecs <= 0) 74 return false; 75 else { 76 long waitTime = msecs; 77 long start = System.currentTimeMillis(); 78 for (;;) { 79 wait(waitTime); 80 if (latched_) 81 return true; 82 else { 83 waitTime = msecs - (System.currentTimeMillis() - start); 84 if (waitTime <= 0) 85 return false; 86 } 87 } 88 } 89 } 90 } 91 92 93 public synchronized void release() { 94 latched_ = true; 95 notifyAll(); 96 } 97 98 } 99 100
| Popular Tags
|