public class ThreadPoolUtils extends Object
| Constructor and Description |
|---|
ThreadPoolUtils() |
| Modifier and Type | Method and Description |
|---|---|
static ThreadPoolExecutor |
createCachedThreadPool(int threadNum,
String namePrefix)
Create a thread pool with max thread number.
|
static <U,T> Iterator<T> |
randomlyExecute(ExecutorService executor,
java.util.function.Function<U,List<T>> processor,
Collection<U> input) |
static <U> void |
randomlyOnlyExecute(ExecutorService executor,
java.util.function.Consumer<U> processor,
Collection<U> input) |
static <T,U> Iterable<T> |
sequentialBatchedExecute(ThreadPoolExecutor executor,
java.util.function.Function<U,List<T>> processor,
List<U> input,
Integer queueSize)
This method aims to parallel process tasks with memory control and sequentially.
|
public static ThreadPoolExecutor createCachedThreadPool(int threadNum, String namePrefix)
The Executors.newCachedThreadPool() cannot limit max thread number. Non-core threads
must be used with SynchronousQueue, but synchronous queue will be blocked when there
is max thread number.
public static <T,U> Iterable<T> sequentialBatchedExecute(ThreadPoolExecutor executor, java.util.function.Function<U,List<T>> processor, List<U> input, @Nullable Integer queueSize)
public static <U> void randomlyOnlyExecute(ExecutorService executor, java.util.function.Consumer<U> processor, Collection<U> input)
public static <U,T> Iterator<T> randomlyExecute(ExecutorService executor, java.util.function.Function<U,List<T>> processor, Collection<U> input)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.