Class ExecutorQueue
- java.lang.Object
-
- org.simpleframework.common.thread.ExecutorQueue
-
class ExecutorQueue extends java.lang.Object
TheExecutorQueue
object is used to queue tasks in a thread pool. This creates a thread pool with no limit to the number of tasks that can be enqueued, which ensures that any system requesting a task to be executed will not block when handing it over, it also means the user must use caution.- See Also:
ConcurrentExecutor
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ThreadPoolExecutor
executor
This is the actual thread pool implementation used.private java.util.concurrent.ThreadFactory
factory
This is used to create the pool worker threads.private java.util.concurrent.BlockingQueue<java.lang.Runnable>
queue
This is the task queue that contains tasks due to execute.
-
Constructor Summary
Constructors Constructor Description ExecutorQueue(java.lang.Class type, int rest, int active)
Constructor for theExecutorQueue
object.ExecutorQueue(java.lang.Class type, int rest, int active, long duration, java.util.concurrent.TimeUnit unit)
Constructor for theExecutorQueue
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(java.lang.Runnable task)
Theexecute
method is used to queue the task for execution.void
stop()
This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.void
stop(long wait)
This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.
-
-
-
Field Detail
-
queue
private final java.util.concurrent.BlockingQueue<java.lang.Runnable> queue
This is the task queue that contains tasks due to execute.
-
executor
private final java.util.concurrent.ThreadPoolExecutor executor
This is the actual thread pool implementation used.
-
factory
private final java.util.concurrent.ThreadFactory factory
This is used to create the pool worker threads.
-
-
Constructor Detail
-
ExecutorQueue
public ExecutorQueue(java.lang.Class type, int rest, int active)
Constructor for theExecutorQueue
object. This is used to create a pool of threads that can be used to execute arbitraryRunnable
tasks. If the threads are busy this will simply enqueue the tasks and return.- Parameters:
type
- this is the type of runnable that this acceptsrest
- this is the number of threads to use in the poolactive
- this is the maximum size the pool can grow to
-
ExecutorQueue
public ExecutorQueue(java.lang.Class type, int rest, int active, long duration, java.util.concurrent.TimeUnit unit)
Constructor for theExecutorQueue
object. This is used to create a pool of threads that can be used to execute arbitraryRunnable
tasks. If the threads are busy this will simply enqueue the tasks and return.- Parameters:
type
- this is the type of runnable that this acceptsrest
- this is the number of threads to use in the poolactive
- this is the maximum size the pool can grow toduration
- the duration active threads remain idle forunit
- this is the time unit used for the duration
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable task)
Theexecute
method is used to queue the task for execution. If all threads are busy the provided task is queued and waits until all current and outstanding tasks are finished.- Parameters:
task
- this is the task to be queued for execution
-
stop
public void stop()
This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.
-
stop
public void stop(long wait)
This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.- Parameters:
wait
- the number of milliseconds to wait for it to stop
-
-