private void startReservedThread() { try { while (true) { // Not atomic, but there is a re-check in ReservedThread.run(). int pending = _pending.get(); int size = _size.get(); if (pending + size >= _capacity) return; if (_pending.compareAndSet(pending, pending + 1)) { if (LOG.isDebugEnabled()) LOG.debug("{} startReservedThread p={}", this, pending + 1); _executor.execute(new ReservedThread()); return; } } } catch(RejectedExecutionException e) { LOG.ignore(e); } }
/** * @param task The task to run * @return True iff a reserved thread was available and has been assigned the task to run. */ @Override public boolean tryExecute(Runnable task) { if (LOG.isDebugEnabled()) LOG.debug("{} tryExecute {}",this ,task); if (task==null) return false; ReservedThread thread = _stack.pollFirst(); if (thread==null) { if (task!=STOP) startReservedThread(); return false; } int size = _size.decrementAndGet(); thread.offer(task); if (size==0 && task!=STOP) startReservedThread(); return true; }
Runnable task = reservedWait();
Runnable task = reservedWait();
private void startReservedThread() { try { while (true) { // Not atomic, but there is a re-check in ReservedThread.run(). int pending = _pending.get(); int size = _size.get(); if (pending + size >= _capacity) return; if (_pending.compareAndSet(pending, pending + 1)) { if (LOG.isDebugEnabled()) LOG.debug("{} startReservedThread p={}", this, pending + 1); _executor.execute(new ReservedThread()); return; } } } catch(RejectedExecutionException e) { LOG.ignore(e); } }
/** * @param task The task to run * @return True iff a reserved thread was available and has been assigned the task to run. */ @Override public boolean tryExecute(Runnable task) { if (LOG.isDebugEnabled()) LOG.debug("{} tryExecute {}",this ,task); if (task==null) return false; ReservedThread thread = _stack.pollFirst(); if (thread==null) { if (task!=STOP) startReservedThread(); return false; } int size = _size.decrementAndGet(); thread.offer(task); if (size==0 && task!=STOP) startReservedThread(); return true; }
@Override public void doStop() throws Exception { if (_lease!=null) _lease.close(); while(true) { ReservedThread thread = _stack.pollFirst(); if (thread == null) break; _size.decrementAndGet(); thread.stop(); } super.doStop(); }
public void stop() { offer(STOP); }
@Override public void doStop() throws Exception { if (_lease!=null) _lease.close(); while(true) { ReservedThread thread = _stack.pollFirst(); if (thread == null) break; _size.decrementAndGet(); thread.stop(); } super.doStop(); }
public void stop() { offer(STOP); }