public interface ConcurrentUtils
| Modifier and Type | Method and Description |
|---|---|
static ExecutorService |
newCachedThreadPool(int maximumPoolSize,
ThreadFactory threadFactory)
The same as
Executors.newCachedThreadPool(ThreadFactory)
except that this method takes a maximumPoolSize parameter. |
static ThreadFactory |
newThreadFactory(String namePrefix)
Creates a
ThreadFactory so that the threads created by the factory are named with the given name prefix. |
static ExecutorService |
newThreadPoolWithMax(boolean cached,
int maximumPoolSize,
String namePrefix)
Create a new
ExecutorService with a maximum pool size. |
static <T> CompletableFuture<Void> |
parallelForEachAsync(Collection<T> collection,
Consumer<? super T> action,
Executor executor)
The same as collection.parallelStream().forEach(action) except that
(1) this method is asynchronous, and
(2) an executor can be passed to this method.
|
static void |
shutdownAndWait(ExecutorService executor)
Shutdown the given executor and wait for its termination.
|
static void |
shutdownAndWait(TimeDuration waitTime,
ExecutorService executor,
Consumer<TimeDuration> timoutHandler) |
static <E,THROWABLE extends Throwable> |
updateAndGet(AtomicReference<E> reference,
CheckedFunction<E,E,THROWABLE> update)
Similar to
AtomicReference.updateAndGet(java.util.function.UnaryOperator)
except that the update function is checked. |
static <E,THROWABLE extends Throwable> E updateAndGet(AtomicReference<E> reference, CheckedFunction<E,E,THROWABLE> update) throws THROWABLE extends Throwable
AtomicReference.updateAndGet(java.util.function.UnaryOperator)
except that the update function is checked.THROWABLE extends Throwablestatic ThreadFactory newThreadFactory(String namePrefix)
ThreadFactory so that the threads created by the factory are named with the given name prefix.namePrefix - the prefix used in the name of the threads created.ThreadFactory.static ExecutorService newCachedThreadPool(int maximumPoolSize, ThreadFactory threadFactory)
Executors.newCachedThreadPool(ThreadFactory)
except that this method takes a maximumPoolSize parameter.maximumPoolSize - the maximum number of threads to allow in the pool.
When maximumPoolSize == 0, this method is the same as
Executors.newCachedThreadPool(ThreadFactory).ExecutorService.static ExecutorService newThreadPoolWithMax(boolean cached, int maximumPoolSize, String namePrefix)
ExecutorService with a maximum pool size.
If it is cached, this method is similar to newCachedThreadPool(int, ThreadFactory).
Otherwise, this method is similar to Executors.newFixedThreadPool(int).cached - Use cached thread pool? If not, use a fixed thread pool.maximumPoolSize - the maximum number of threads to allow in the pool.namePrefix - the prefix used in the name of the threads created.ExecutorService.static void shutdownAndWait(ExecutorService executor)
executor - The executor to be shut down.static void shutdownAndWait(TimeDuration waitTime, ExecutorService executor, Consumer<TimeDuration> timoutHandler)
static <T> CompletableFuture<Void> parallelForEachAsync(Collection<T> collection, Consumer<? super T> action, Executor executor)
T - The element type.collection - The given collection.action - To act on each element in the collection.executor - To execute the action.CompletableFuture that is completed
when the action is completed for each element in the collection.Collection.parallelStream(),
Stream.forEach(Consumer)Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.