public interface ConcurrentUtils
| 限定符和类型 | 方法和说明 |
|---|---|
static <E,THROWABLE extends Throwable> |
accept(CheckedConsumer<? super E,THROWABLE> action,
E element,
CompletableFuture<E> f) |
static ExecutorService |
newCachedThreadPool(int maximumPoolSize,
ThreadFactory threadFactory)
The same as
Executors.newCachedThreadPool(ThreadFactory)
except that this method takes a maximumPoolSize parameter. |
static ExecutorService |
newSingleThreadExecutor(String name)
This method is similar to
Executors.newSingleThreadExecutor(ThreadFactory)
except that this method takes a specific thread name as there is only one thread.g |
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 <E,THROWABLE extends Throwable> |
parallelForEachAsync(Collection<E> collection,
CheckedConsumer<? super E,THROWABLE> action,
Executor executor)
The same as parallelForEachAsync(collection.stream(), collection.size(), action, executor).
|
static <THROWABLE extends Throwable> |
parallelForEachAsync(int size,
CheckedConsumer<Integer,THROWABLE> action,
Executor executor)
The same as parallelForEachAsync(collection.stream(), collection.size(), action, executor).
|
static <E,THROWABLE extends Throwable> |
parallelForEachAsync(Stream<E> stream,
int size,
CheckedConsumer<? super E,THROWABLE> action,
Executor executor)
The same as
Collection.parallelStream().forEach(action) except that
(1) this method is asynchronous,
(2) this method has an executor parameter, and
(3) the action can throw a checked exception. |
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 newSingleThreadExecutor(String name)
Executors.newSingleThreadExecutor(ThreadFactory)
except that this method takes a specific thread name as there is only one thread.gname - the thread name for only one thread.ExecutorService.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 <E,THROWABLE extends Throwable> CompletableFuture<Void> parallelForEachAsync(Stream<E> stream, int size, CheckedConsumer<? super E,THROWABLE> action, Executor executor)
Collection.parallelStream().forEach(action) except that
(1) this method is asynchronous,
(2) this method has an executor parameter, and
(3) the action can throw a checked exception.E - The element type.THROWABLE - the exception type.stream - The stream to be processed.size - The estimated size of the stream.action - To act on each element in the stream.executor - To execute the action.CompletableFuture that is completed
when the action is completed for each element in the collection.
When the action throws an exception, the future will be completed exceptionally.Collection.parallelStream(),
Stream.forEach(Consumer)static <E,THROWABLE extends Throwable> CompletableFuture<Void> parallelForEachAsync(Collection<E> collection, CheckedConsumer<? super E,THROWABLE> action, Executor executor)
static <THROWABLE extends Throwable> CompletableFuture<Void> parallelForEachAsync(int size, CheckedConsumer<Integer,THROWABLE> action, Executor executor)
static <E,THROWABLE extends Throwable> void accept(CheckedConsumer<? super E,THROWABLE> action, E element, CompletableFuture<E> f)
Copyright © 2017–2023 The Apache Software Foundation. All rights reserved.