Package org.biojava.nbio.core.util
Class ConcurrencyTools
java.lang.Object
org.biojava.nbio.core.util.ConcurrencyTools
Static utility to easily share a thread pool for concurrent/parallel/lazy execution.  To exit cleanly,
 
shutdown() or shutdownAndAwaitTermination() must be called after all tasks have been submitted.- Author:
 - Mark Chapman
 
- 
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadPoolExecutorReturns current shared thread pool.static voidSets thread pool to any givenThreadPoolExecutorto allow use of an alternative execution style.static voidsetThreadPoolCPUsAvailable(int cpus) Sets thread pool to reserve a given number of processor cores for foreground or other use.static voidsetThreadPoolCPUsFraction(float fraction) Sets thread pool to a given fraction of the available processors.static voidSets thread pool to default of 1 background thread for each processor core.static voidSets thread pool to a single background thread.static voidsetThreadPoolSize(int threads) Sets thread pool to given size.static voidshutdown()Disables new tasks from being submitted and closes the thread pool cleanly.static voidCloses the thread pool.static <T> Future<T>Queues up a task and adds a default log entry.static <T> Future<T>Queues up a task and adds a log entry. 
- 
Method Details
- 
getThreadPool
Returns current shared thread pool. Starts up a new pool, if necessary.- Returns:
 - shared thread pool
 
 - 
setThreadPoolCPUsAvailable
public static void setThreadPoolCPUsAvailable(int cpus) Sets thread pool to reserve a given number of processor cores for foreground or other use.- Parameters:
 cpus- number of processor cores to reserve
 - 
setThreadPoolCPUsFraction
public static void setThreadPoolCPUsFraction(float fraction) Sets thread pool to a given fraction of the available processors.- Parameters:
 fraction- portion of available processors to use in thread pool
 - 
setThreadPoolDefault
public static void setThreadPoolDefault()Sets thread pool to default of 1 background thread for each processor core. - 
setThreadPoolSingle
public static void setThreadPoolSingle()Sets thread pool to a single background thread. - 
setThreadPoolSize
public static void setThreadPoolSize(int threads) Sets thread pool to given size.- Parameters:
 threads- number of threads in pool
 - 
setThreadPool
Sets thread pool to any givenThreadPoolExecutorto allow use of an alternative execution style.- Parameters:
 pool- thread pool to share
 - 
shutdown
public static void shutdown()Disables new tasks from being submitted and closes the thread pool cleanly. - 
shutdownAndAwaitTermination
public static void shutdownAndAwaitTermination()Closes the thread pool. Waits 1 minute for a clean exit; if necessary, waits another minute for cancellation. - 
submit
Queues up a task and adds a log entry.- Type Parameters:
 T- type returned from the submitted task- Parameters:
 task- submitted taskmessage- logged message- Returns:
 - future on which the desired value is retrieved by calling get()
 
 - 
submit
Queues up a task and adds a default log entry.- Type Parameters:
 T- type returned from the submitted task- Parameters:
 task- submitted task- Returns:
 - future on which the desired value is retrieved by calling get()
 
 
 -