public final class ConcurrencyUtil
extends java.lang.Object
Constructor and Description |
---|
ConcurrencyUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
awaitQuiescence(java.util.concurrent.ThreadPoolExecutor executor,
long timeout,
java.util.concurrent.TimeUnit unit)
Awaits for all tasks in the
executor to finish for the specified timeout |
static <T> T |
cacheOrGet(java.util.concurrent.atomic.AtomicReference<T> ref,
T defaultValue) |
static <K,V> V |
cacheOrGet(java.util.concurrent.ConcurrentMap<K,V> map,
K key,
V defaultValue) |
static void |
getAll(java.util.Collection<? extends java.util.concurrent.Future<?>> futures) |
static <T> java.util.List<java.util.concurrent.Future<T>> |
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
java.util.concurrent.ExecutorService executorService)
Invokes and waits all tasks using threadPool, avoiding thread starvation on the way
(see "A Thread Pool Puzzler").
|
static void |
joinAll(java.util.Collection<? extends java.lang.Thread> threads) |
static void |
joinAll(java.lang.Thread... threads) |
static java.util.concurrent.ThreadFactory |
newNamedThreadFactory(java.lang.String name) |
static java.util.concurrent.ThreadFactory |
newNamedThreadFactory(java.lang.String name,
boolean isDaemon,
int priority) |
static java.util.concurrent.ExecutorService |
newSameThreadExecutorService()
Service which executes tasks synchronously immediately after they submitted
|
static java.util.concurrent.ScheduledThreadPoolExecutor |
newSingleScheduledThreadExecutor(java.lang.String name) |
static java.util.concurrent.ScheduledThreadPoolExecutor |
newSingleScheduledThreadExecutor(java.lang.String name,
int priority) |
static java.util.concurrent.ThreadPoolExecutor |
newSingleThreadExecutor(java.lang.String name) |
static java.util.concurrent.ThreadPoolExecutor |
newSingleThreadExecutor(java.lang.String name,
int priority) |
static java.lang.Runnable |
once(java.lang.Runnable delegate) |
static void |
runUnderThreadName(java.lang.String name,
java.lang.Runnable runnable) |
static java.lang.Runnable |
underThreadNameRunnable(java.lang.String name,
java.lang.Runnable runnable) |
static <T,E extends java.lang.Throwable> |
withLock(java.util.concurrent.locks.Lock lock,
ThrowableComputable<T,E> runnable) |
static <E extends java.lang.Throwable> |
withLock(java.util.concurrent.locks.Lock lock,
ThrowableRunnable<E> runnable) |
public static <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, java.util.concurrent.ExecutorService executorService) throws java.lang.Throwable
java.lang.Throwable
public static <K,V> V cacheOrGet(java.util.concurrent.ConcurrentMap<K,V> map, K key, V defaultValue)
public static <T> T cacheOrGet(java.util.concurrent.atomic.AtomicReference<T> ref, T defaultValue)
public static java.util.concurrent.ThreadPoolExecutor newSingleThreadExecutor(java.lang.String name)
public static java.util.concurrent.ThreadPoolExecutor newSingleThreadExecutor(java.lang.String name, int priority)
public static java.util.concurrent.ScheduledThreadPoolExecutor newSingleScheduledThreadExecutor(java.lang.String name)
public static java.util.concurrent.ScheduledThreadPoolExecutor newSingleScheduledThreadExecutor(java.lang.String name, int priority)
public static java.util.concurrent.ExecutorService newSameThreadExecutorService()
public static java.util.concurrent.ThreadFactory newNamedThreadFactory(java.lang.String name, boolean isDaemon, int priority)
public static java.util.concurrent.ThreadFactory newNamedThreadFactory(java.lang.String name)
public static void awaitQuiescence(java.util.concurrent.ThreadPoolExecutor executor, long timeout, java.util.concurrent.TimeUnit unit)
executor
to finish for the specified timeout
public static void joinAll(java.util.Collection<? extends java.lang.Thread> threads) throws java.lang.RuntimeException
java.lang.RuntimeException
public static void joinAll(java.lang.Thread... threads) throws java.lang.RuntimeException
java.lang.RuntimeException
public static void getAll(java.util.Collection<? extends java.util.concurrent.Future<?>> futures) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
public static java.lang.Runnable underThreadNameRunnable(java.lang.String name, java.lang.Runnable runnable)
public static void runUnderThreadName(java.lang.String name, java.lang.Runnable runnable)
public static java.lang.Runnable once(java.lang.Runnable delegate)
public static <T,E extends java.lang.Throwable> T withLock(java.util.concurrent.locks.Lock lock, ThrowableComputable<T,E> runnable) throws E extends java.lang.Throwable
E extends java.lang.Throwable
public static <E extends java.lang.Throwable> void withLock(java.util.concurrent.locks.Lock lock, ThrowableRunnable<E> runnable) throws E extends java.lang.Throwable
E extends java.lang.Throwable