DelegatingThreadPool as TryExecutor

Noticed while looking at #2718, it is more efficient if tryExecute semantics are available.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-09-12 16:42:05 +10:00
parent aebe436e00
commit 4b461b7556
1 changed files with 13 additions and 6 deletions

View File

@ -25,19 +25,18 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.eclipse.jetty.util.thread.TryExecutor;
public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool
{
private static final Logger LOG = Log.getLogger(DelegatingThreadPool.class);
public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool, TryExecutor
{
private Executor _executor; // memory barrier provided by start/stop semantics
private TryExecutor _tryExecutor;
public DelegatingThreadPool(Executor executor)
{
_executor=executor;
_tryExecutor=TryExecutor.asTryExecutor(executor);
addBean(_executor);
}
@ -54,6 +53,7 @@ public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPo
throw new IllegalStateException(getState());
updateBean(_executor,executor);
_executor=executor;
_tryExecutor=TryExecutor.asTryExecutor(executor);
}
/* ------------------------------------------------------------ */
@ -63,6 +63,13 @@ public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPo
_executor.execute(job);
}
/* ------------------------------------------------------------ */
@Override
public boolean tryExecute(Runnable task)
{
return _tryExecutor.tryExecute(task);
}
/* ------------------------------------------------------------ */
@Override
public int getIdleThreads()