Package org.simpleframework.util.thread
Class Scheduler
- java.lang.Object
-
- org.simpleframework.util.thread.Scheduler
-
- All Implemented Interfaces:
java.util.concurrent.Executor
public class Scheduler extends java.lang.Object implements java.util.concurrent.Executor
TheScheduler
object is used to schedule tasks for execution. This queues the task for the requested period of time before it is executed. It ensures that the delay is adhered to such that tasks can be timed for execution in an accurate way.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description Scheduler(int size)
Constructor for theScheduler
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(java.lang.Runnable task)
This will execute the task within the executor immediately as it uses a delay duration of zero milliseconds.void
execute(java.lang.Runnable task, long delay)
This will execute the task within the executor after the time specified has expired.void
execute(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
This will execute the task within the executor after the time specified has expired.void
stop()
This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.
-
-
-
Constructor Detail
-
Scheduler
public Scheduler(int size)
Constructor for theScheduler
object. This will create a scheduler with a fixed number of threads to use before execution. Depending on the types of task that are to be executed this should be increased for accuracy.- Parameters:
size
- this is the number of threads for the scheduler
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable task)
This will execute the task within the executor immediately as it uses a delay duration of zero milliseconds. This can be used if the scheduler is to be used as a thread pool.- Specified by:
execute
in interfacejava.util.concurrent.Executor
- Parameters:
task
- this is the task to schedule for execution
-
execute
public void execute(java.lang.Runnable task, long delay)
This will execute the task within the executor after the time specified has expired. If the time specified is zero then it will be executed immediately. Once the scheduler has been stopped then this method will no longer accept runnable tasks.- Parameters:
task
- this is the task to schedule for executiondelay
- the time in milliseconds to wait for execution
-
execute
public void execute(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)
This will execute the task within the executor after the time specified has expired. If the time specified is zero then it will be executed immediately. Once the scheduler has been stopped then this method will no longer accept runnable tasks.- Parameters:
task
- this is the task to schedule for executiondelay
- this is the delay to wait before executionunit
- this is the duration time unit to wait for
-
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 immediately once it has been stopped, and not further tasks will be accepted by this pool for execution.
-
-