public synchronized void dispose() { List<SchedulerListener> l = listeners; listeners = null; if (l != null) { boolean cont = true; while (cont) { synchronized (l) { int queueSize = getQueueSize(); if (queueSize == 0) { cont = false; } else { try { l.wait(); } catch (InterruptedException ex) { // Ignore! } } } } synchronized (l) { l.clear(); } } }
public void run() { while (remainingJobs() > 0) { Object input = null; synchronized (pool) { while (pool.isEmpty()) { if (remainingJobs() == 0) { return; } try { pool.wait(); } catch (InterruptedException e) { } } input = pool.remove(pool.size() - 1); process(input); jobsDone++; } // end if } // end while }
/** * Stops this <tt>ContactSourceService</tt> implementation and prepares it for garbage collection. * * @see AsyncContactSourceService#stop() */ public void stop() { boolean interrupted = false; synchronized (queries) { while (!queries.isEmpty()) { queries.get(0).cancel(); try { queries.wait(); } catch (InterruptedException iex) { interrupted = true; } } } if (interrupted) Thread.currentThread().interrupt(); }