/** * Creates a new waiting thread. * Called by {@link #getRoutePool} when necessary. * * @param cond the condition to wait for * @param rospl the route specific pool, or <code>null</code> * * @return a waiting thread representation */ protected WaitingThread newWaitingThread(Condition cond, RouteSpecificPool rospl) { return new WaitingThread(cond, rospl); }
rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline);
/** * Sets the waiting thread. If this has already been aborted, * the waiting thread is immediately interrupted. * * @param waitingThread The thread to interrupt when aborting. */ public void setWaitingThread(WaitingThread waitingThread) { this.waitingThread = waitingThread; if (aborted) waitingThread.interrupt(); }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
waitingThread.wakeup();
/** * If a waiting thread has been set, interrupts it. */ public void abort() { aborted = true; if (waitingThread != null) waitingThread.interrupt(); }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
/** * Creates a new waiting thread. * Called by {@link #getRoutePool} when necessary. * * @param cond the condition to wait for * @param rospl the route specific pool, or <code>null</code> * * @return a waiting thread representation */ protected WaitingThread newWaitingThread(Condition cond, RouteSpecificPool rospl) { return new WaitingThread(cond, rospl); }
rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline);
/** * If a waiting thread has been set, interrupts it. */ public void abort() { aborted = true; if (waitingThread != null) waitingThread.interrupt(); }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
/** * Creates a new waiting thread. * Called by {@link #getRoutePool} when necessary. * * @param cond the condition to wait for * @param rospl the route specific pool, or {@code null} * * @return a waiting thread representation */ protected WaitingThread newWaitingThread(final Condition cond, final RouteSpecificPool rospl) { return new WaitingThread(cond, rospl); }
rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline);
/** * Sets the waiting thread. If this has already been aborted, * the waiting thread is immediately interrupted. * * @param waitingThread The thread to interrupt when aborting. */ public void setWaitingThread(WaitingThread waitingThread) { this.waitingThread = waitingThread; if (aborted) waitingThread.interrupt(); }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
final Thread [] threads = new Thread[25]; for(int i = 0; i < 25; i++) { if(i == 0) { threads[i] = new WaitinThread(null); } else { threads[i] = new WaitingThread(threads[i - 1]); } }
rospl.queueThread(waitingThread); waitingThreads.add(waitingThread); success = waitingThread.await(deadline);
/** * If a waiting thread has been set, interrupts it. */ public void abort() { aborted = true; if (waitingThread != null) { waitingThread.interrupt(); } }
@Override public void shutdown() { poolLock.lock(); try { super.shutdown(); // close all free connections //@@@ move this to base class? Iterator<BasicPoolEntry> ibpe = freeConnections.iterator(); while (ibpe.hasNext()) { BasicPoolEntry entry = ibpe.next(); ibpe.remove(); closeConnection(entry.getConnection()); } // wake up all waiting threads Iterator<WaitingThread> iwth = waitingThreads.iterator(); while (iwth.hasNext()) { WaitingThread waiter = iwth.next(); iwth.remove(); waiter.wakeup(); } routeToPool.clear(); } finally { poolLock.unlock(); } }
/** * Creates a new waiting thread. * Called by {@link #getRoutePool} when necessary. * * @param cond the condition to wait for * @param rospl the route specific pool, or <code>null</code> * * @return a waiting thread representation */ protected WaitingThread newWaitingThread(Condition cond, RouteSpecificPool rospl) { return new WaitingThread(cond, rospl); }