Improved ReservedThreadExecutor by reporting waiting threads.
This commit is contained in:
parent
761dccd10c
commit
0bc8305535
|
@ -63,6 +63,7 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
||||||
private final ConcurrentStack.NodeStack<ReservedThread> _stack;
|
private final ConcurrentStack.NodeStack<ReservedThread> _stack;
|
||||||
private final AtomicInteger _size = new AtomicInteger();
|
private final AtomicInteger _size = new AtomicInteger();
|
||||||
private final AtomicInteger _pending = new AtomicInteger();
|
private final AtomicInteger _pending = new AtomicInteger();
|
||||||
|
private final AtomicInteger _waiting = new AtomicInteger();
|
||||||
|
|
||||||
private ThreadPoolBudget.Lease _lease;
|
private ThreadPoolBudget.Lease _lease;
|
||||||
private Object _owner;
|
private Object _owner;
|
||||||
|
@ -144,6 +145,12 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
||||||
return _pending.get();
|
return _pending.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManagedAttribute(value = "waiting reserved threads", readonly = true)
|
||||||
|
public int getWaiting()
|
||||||
|
{
|
||||||
|
return _waiting.get();
|
||||||
|
}
|
||||||
|
|
||||||
@ManagedAttribute(value = "idletimeout in MS", readonly = true)
|
@ManagedAttribute(value = "idletimeout in MS", readonly = true)
|
||||||
public long getIdleTimeoutMs()
|
public long getIdleTimeoutMs()
|
||||||
{
|
{
|
||||||
|
@ -256,9 +263,13 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
if (_owner==null)
|
return String.format("%s@%s{s=%d/%d,p=%d,w=%d}",
|
||||||
return String.format("%s@%x{s=%d/%d,p=%d}",this.getClass().getSimpleName(),hashCode(),_size.get(),_capacity,_pending.get());
|
getClass().getSimpleName(),
|
||||||
return String.format("%s@%s{s=%d/%d,p=%d}",this.getClass().getSimpleName(),_owner,_size.get(),_capacity,_pending.get());
|
_owner != null ? _owner : Integer.toHexString(hashCode()),
|
||||||
|
_size.get(),
|
||||||
|
_capacity,
|
||||||
|
_pending.get(),
|
||||||
|
_waiting.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ReservedThread extends ConcurrentStack.Node implements Runnable
|
private class ReservedThread extends ConcurrentStack.Node implements Runnable
|
||||||
|
@ -301,6 +312,7 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_waiting.incrementAndGet();
|
||||||
if (_idleTime == 0)
|
if (_idleTime == 0)
|
||||||
_wakeup.await();
|
_wakeup.await();
|
||||||
else
|
else
|
||||||
|
@ -310,6 +322,10 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements Executo
|
||||||
{
|
{
|
||||||
LOG.ignore(e);
|
LOG.ignore(e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_waiting.decrementAndGet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
task = _task;
|
task = _task;
|
||||||
_task = null;
|
_task = null;
|
||||||
|
|
Loading…
Reference in New Issue