org.encog.util.concurrency
Class EngineConcurrency
- java.lang.Object
-
- org.encog.util.concurrency.EngineConcurrency
-
- All Implemented Interfaces:
- MultiThreadable
public class EngineConcurrency extends java.lang.Object implements MultiThreadable
This class abstracts thread pools, and potentially grids and other types of concurrency. It is used by other classes inside of Encog to allow tasks to be executed efficiently on multicore machines.
-
-
Constructor Summary
Constructors Constructor and Description EngineConcurrency()Construct a concurrency object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidcheckError()Check to see if one of the threads has thrown an error.TaskGroupcreateTaskGroup()Create a new task group.static EngineConcurrencygetInstance()intgetThreadCount()voidprocessTask(EngineTask task)Process the specified task.voidprocessTask(EngineTask task, TaskGroup group)Process the specified task.voidregisterError(java.lang.Throwable t)Allows threads to register errors, these errors will be thrown by the main thread.voidsetThreadCount(int t)Set the number of threads to use.voidshutdown(long timeout)Wait for all threads in the pool to complete.
-
-
-
Method Detail
-
getInstance
public static EngineConcurrency getInstance()
- Returns:
- The instance to the singleton.
-
setThreadCount
public void setThreadCount(int t)
Set the number of threads to use.- Specified by:
setThreadCountin interfaceMultiThreadable- Parameters:
t- The number of threads to use, or zero to automatically determine based on core count.
-
checkError
public void checkError()
Check to see if one of the threads has thrown an error. If so, then throw that error.
-
createTaskGroup
public TaskGroup createTaskGroup()
Create a new task group.- Returns:
- The new task group.
-
processTask
public void processTask(EngineTask task)
Process the specified task.- Parameters:
task- The task to process.
-
processTask
public void processTask(EngineTask task, TaskGroup group)
Process the specified task. It will be processed either now, or queued to process on the thread pool.- Parameters:
task- The task to process.group- The task group.
-
registerError
public void registerError(java.lang.Throwable t)
Allows threads to register errors, these errors will be thrown by the main thread.- Parameters:
t- The error to register.
-
shutdown
public void shutdown(long timeout)
Wait for all threads in the pool to complete.- Parameters:
timeout- How long to wait for all threads to complete.
-
getThreadCount
public int getThreadCount()
- Specified by:
getThreadCountin interfaceMultiThreadable- Returns:
- The number of threads to use, 0 to automatically determine based on core count.
-
-
DMelt 3.0 © DataMelt by jWork.ORG