public class ConcurrencyUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static long |
getConcurrentThreshold()
Returns the minimum length of array for which multiple threads are used.
|
static int |
getNumberOfProcessors()
Returns the number of available processors.
|
static int |
getNumberOfThreads()
Returns the current number of threads.
|
static ExecutorService |
getThreadPool()
Returns the pool of threads.
|
static void |
setConcurrentThreshold(long concurrentThreshold)
Sets the minimum length of an array for which multiple threads are used.
|
static void |
setNumberOfThreads(int n)
Sets the number of threads.
|
static void |
setThreadPool(ExecutorService threadPool)
Sets the pool of threads.
|
static void |
shutdownThreadPoolAndAwaitTermination()
Shutdowns all submitted tasks.
|
static <T> Future<T> |
submit(Callable<T> task)
Submits a value-returning task for execution and returns a Future
representing the pending results of the task.
|
static Future<?> |
submit(Runnable task)
Submits a Runnable task for execution and returns a Future representing that task.
|
static void |
waitForCompletion(Future<?>[] futures)
Waits for all threads to complete computation.
|
public static long getConcurrentThreshold()
public static void setConcurrentThreshold(long concurrentThreshold)
concurrentThreshold - minimum length of an array for which multiple threads are usedpublic static int getNumberOfProcessors()
public static int getNumberOfThreads()
public static void setNumberOfThreads(int n)
n - new value of threadspublic static <T> Future<T> submit(Callable<T> task)
T - typetask - task for execution
public static Future<?> submit(Runnable task)
task - task for execution
public static void waitForCompletion(Future<?>[] futures) throws InterruptedException, ExecutionException
futures - list of handles to the tasks
ExecutionException - if the computation threw an exceptionInterruptedException - if the current thread was interrupted while waitingpublic static void setThreadPool(ExecutorService threadPool)
threadPool - pool of threadspublic static ExecutorService getThreadPool()
public static void shutdownThreadPoolAndAwaitTermination()
Copyright © 2015. All rights reserved.