@Override public void run() { try { job.run(); return; } catch (Throwable e) { handleUnexpectedException(e); } finally { done.countDown(); /* * clear the interrupt status so that this thread can be reused * for other jobs */ Thread.interrupted(); } }
/** * 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; }