/** * Waits until all computations are done * * @throws InterruptedException * if was interrupted while waiting */ public synchronized void waitDone() throws InterruptedException { try { done.await(); } catch (InterruptedException e) { checkException(); throw e; } canStart = true; }
/** * Interrupting all threads of this executor (used to wake up waiting * threads if something needs to be notified) */ public void interrupt() { checkException(); threadGroup.interrupt(); }
/** * Starts a several copies of jobs. The jobs cannot be started again until * the method {@link #waitDone()} is called * * @param job * @param noCopies * @return {@code true} if the jobs have been started */ public synchronized boolean start(Runnable job, int noCopies) { if (!canStart) return false; this.done = new CountDownLatch(noCopies); Worker worker = new Worker(job, done, Thread.currentThread()); for (int i = 0; i < noCopies; i++) { execute(worker); } canStart = false; checkException(); return true; }