public final class ThreadUtils
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
private |
ThreadUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
createDefaultInstance(java.lang.Class<?> anchor,
java.lang.Class<T> targetType,
java.lang.String className) |
static <T> T |
createDefaultInstance(java.lang.ClassLoader cl,
java.lang.Class<T> targetType,
java.lang.String className) |
static <T> T |
createDefaultInstance(java.lang.Iterable<? extends java.lang.ClassLoader> cls,
java.lang.Class<T> targetType,
java.lang.String className) |
static java.util.Iterator<java.lang.ClassLoader> |
iterateDefaultClassLoaders(java.lang.Class<?> anchor) |
static CloseableExecutorService |
newCachedThreadPool(java.lang.String poolName) |
static CloseableExecutorService |
newCachedThreadPoolIf(CloseableExecutorService executorService,
java.lang.String poolName) |
static CloseableExecutorService |
newFixedThreadPool(java.lang.String poolName,
int nThreads) |
static CloseableExecutorService |
newFixedThreadPoolIf(CloseableExecutorService executorService,
java.lang.String poolName,
int nThreads) |
static CloseableExecutorService |
newSingleThreadExecutor(java.lang.String poolName) |
static java.util.concurrent.ScheduledExecutorService |
newSingleThreadScheduledExecutor(java.lang.String poolName) |
static CloseableExecutorService |
noClose(CloseableExecutorService executorService) |
static CloseableExecutorService |
protectExecutorServiceShutdown(CloseableExecutorService executorService,
boolean shutdownOnExit)
Wraps an
CloseableExecutorService in such a way as to "protect"
it for calls to the ExecutorService.shutdown() or
ExecutorService.shutdownNow() . |
static java.lang.ClassLoader |
resolveDefaultClassLoader(java.lang.Class<?> anchor)
Attempts to find the most suitable
ClassLoader as follows: |
static java.lang.ClassLoader |
resolveDefaultClassLoader(java.lang.Object anchor) |
static java.lang.Iterable<java.lang.ClassLoader> |
resolveDefaultClassLoaders(java.lang.Class<?> anchor) |
static java.lang.Iterable<java.lang.ClassLoader> |
resolveDefaultClassLoaders(java.lang.Object anchor) |
public static CloseableExecutorService protectExecutorServiceShutdown(CloseableExecutorService executorService, boolean shutdownOnExit)
CloseableExecutorService
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 CloseableExecutorService noClose(CloseableExecutorService executorService)
public static java.lang.ClassLoader resolveDefaultClassLoader(java.lang.Object anchor)
public static java.lang.Iterable<java.lang.ClassLoader> resolveDefaultClassLoaders(java.lang.Object anchor)
public static java.lang.Iterable<java.lang.ClassLoader> resolveDefaultClassLoaders(java.lang.Class<?> anchor)
public static <T> T createDefaultInstance(java.lang.Class<?> anchor, java.lang.Class<T> targetType, java.lang.String className) throws java.lang.ReflectiveOperationException
java.lang.ReflectiveOperationException
public static <T> T createDefaultInstance(java.lang.ClassLoader cl, java.lang.Class<T> targetType, java.lang.String className) throws java.lang.ReflectiveOperationException
java.lang.ReflectiveOperationException
public static <T> T createDefaultInstance(java.lang.Iterable<? extends java.lang.ClassLoader> cls, java.lang.Class<T> targetType, java.lang.String className) throws java.lang.ReflectiveOperationException
java.lang.ReflectiveOperationException
public static java.lang.ClassLoader resolveDefaultClassLoader(java.lang.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 context
class loader - ignored if null
ClassLoader
- Note: might still be null
if went all the way "down" to the system class loader and it was also
null
.public static java.util.Iterator<java.lang.ClassLoader> iterateDefaultClassLoaders(java.lang.Class<?> anchor)
public static CloseableExecutorService newFixedThreadPoolIf(CloseableExecutorService executorService, java.lang.String poolName, int nThreads)
public static CloseableExecutorService newFixedThreadPool(java.lang.String poolName, int nThreads)
public static CloseableExecutorService newCachedThreadPoolIf(CloseableExecutorService executorService, java.lang.String poolName)
public static CloseableExecutorService newCachedThreadPool(java.lang.String poolName)
public static java.util.concurrent.ScheduledExecutorService newSingleThreadScheduledExecutor(java.lang.String poolName)
public static CloseableExecutorService newSingleThreadExecutor(java.lang.String poolName)