public final class ThreadUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ThreadUtils.SshdThreadFactory |
Modifier and Type | Method and Description |
---|---|
static ExecutorService |
newCachedThreadPool(String poolName) |
static ExecutorService |
newFixedThreadPool(String poolName,
int nThreads) |
static ExecutorService |
newSingleThreadExecutor(String poolName) |
static ScheduledExecutorService |
newSingleThreadScheduledExecutor(String poolName) |
static ExecutorService |
protectExecutorServiceShutdown(ExecutorService executorService,
boolean shutdownOnExit)
Wraps an
ExecutorService in such a way as to "protect"
it for calls to the ExecutorService.shutdown() or
ExecutorService.shutdownNow() . |
static ClassLoader |
resolveDefaultClassLoader(Class<?> anchor)
Attempts to find the most suitable
ClassLoader as follows: |
static ClassLoader |
resolveDefaultClassLoader(Object anchor) |
public static ExecutorService protectExecutorServiceShutdown(ExecutorService executorService, boolean shutdownOnExit)
ExecutorService
in such a way as to "protect"
it for calls to the ExecutorService.shutdown()
or
ExecutorService.shutdownNow()
. All other calls are delegated as-is
to the original service. Note: the exposed wrapped proxy will
answer correctly the ExecutorService.isShutdown()
query if indeed
one of the shutdown
methods was invoked.executorService
- The original service - ignored if null
shutdownOnExit
- If true
then it is OK to shutdown the executor
so no wrapping takes place.public static ClassLoader resolveDefaultClassLoader(Object anchor)
public static ClassLoader resolveDefaultClassLoader(Class<?> anchor)
Attempts to find the most suitable ClassLoader
as follows:
Check the Thread.getContextClassLoader()
value
If no thread context class loader then check the anchor class (if given) for its class loader
If still no loader available, then use ClassLoader.getSystemClassLoader()
anchor
- The anchor Class
to use if no current thread
- ignored if null
context class loaderClassLoader
public static ExecutorService newFixedThreadPool(String poolName, int nThreads)
public static ExecutorService newCachedThreadPool(String poolName)
public static ScheduledExecutorService newSingleThreadScheduledExecutor(String poolName)
public static ExecutorService newSingleThreadExecutor(String poolName)
Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.