1 19 20 package org.netbeans.test.web; 21 22 45 public class Waiter { 46 47 private boolean finished = false; 48 49 51 public void init() { 52 synchronized (this) { 53 finished = false; 54 } 55 } 56 57 59 public void waitFinished() throws InterruptedException { 60 synchronized (this) { 61 while (!finished) { 62 wait(); 63 } 64 } 65 } 66 67 72 public boolean waitFinished(long milliseconds) throws InterruptedException { 73 synchronized (this) { 74 if (finished) return true; 75 long expectedEnd = System.currentTimeMillis() + milliseconds; 76 for (;;) { 77 wait(milliseconds); 78 if (finished) return true; 79 long now = System.currentTimeMillis(); 80 if (now >= expectedEnd) return false; 81 milliseconds = expectedEnd - now; 82 } 83 } 84 } 85 86 88 public void notifyFinished() { 89 synchronized (this) { 90 finished = true; 91 notifyAll(); 92 } 93 } 94 } 95 | Popular Tags |