Improved ReservedThreadExecutor by reporting waiting threads.

This commit is contained in:
Simone Bordet 2017-11-09 10:26:11 +01:00
parent 761dccd10c
commit 0bc8305535
1 changed files with 19 additions and 3 deletions

View File

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