public class ThreadScheduler
extends java.lang.Object
ScheduledExecutorService is used.| Constructor and Description |
|---|
ThreadScheduler(boolean daemon,
boolean taskThreads)
Create a new task scheduler.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Thread |
execute(java.lang.Runnable task)
Directly execute a task.
|
java.util.concurrent.ScheduledFuture<?> |
repeat(java.lang.Runnable task,
long repeatDelay)
Repeat a task with a fixed delay.
|
java.util.concurrent.ScheduledFuture<?> |
repeat(java.lang.Runnable task,
long startDelay,
long repeatDelay)
Repeat a task with a fixed delay.
|
java.util.concurrent.ScheduledFuture<?> |
repeat(java.lang.Runnable task,
long startDelay,
long repeatDelay,
java.util.concurrent.TimeUnit timeUnit)
Repeat a task with a fixed delay.
|
java.util.concurrent.ScheduledFuture<?> |
repeat(java.lang.Runnable task,
long repeatDelay,
java.util.concurrent.TimeUnit timeUnit)
Repeat a task with a fixed delay.
|
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable task,
long delay)
Schedule a task to be executed after a delay.
|
java.util.concurrent.ScheduledFuture<?> |
schedule(java.lang.Runnable task,
long delay,
java.util.concurrent.TimeUnit timeUnit)
Schedule a task to be executed after a delay.
|
void |
shutdown()
Shutdown the scheduler.
|
boolean |
shutdown(long timeout)
Shutdown the scheduler and wait for all tasks to finish.
|
boolean |
shutdown(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Shutdown the scheduler and wait for all tasks to finish.
|
public ThreadScheduler(boolean daemon,
boolean taskThreads)
daemon - Whether the scheduler should use daemon threadstaskThreads - Whether the scheduler should use a new thread for each taskpublic java.lang.Thread execute(java.lang.Runnable task)
task - The task to executepublic java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable task,
long delay)
task - The task to executedelay - The delay in millisecondsScheduledFuture of the taskpublic java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable task,
long delay,
java.util.concurrent.TimeUnit timeUnit)
task - The task to executedelay - The delaytimeUnit - The time unit of the delayScheduledFuture of the taskpublic java.util.concurrent.ScheduledFuture<?> repeat(java.lang.Runnable task,
long repeatDelay)
task - The task to executerepeatDelay - The delay between each execution in millisecondsScheduledFuture of the taskpublic java.util.concurrent.ScheduledFuture<?> repeat(java.lang.Runnable task,
long startDelay,
long repeatDelay)
task - The task to executestartDelay - The delay before the first execution in millisecondsrepeatDelay - The delay between each execution in millisecondsScheduledFuture of the taskpublic java.util.concurrent.ScheduledFuture<?> repeat(java.lang.Runnable task,
long repeatDelay,
java.util.concurrent.TimeUnit timeUnit)
task - The task to executerepeatDelay - The delay between each executiontimeUnit - The time unit of the delayScheduledFuture of the taskpublic java.util.concurrent.ScheduledFuture<?> repeat(java.lang.Runnable task,
long startDelay,
long repeatDelay,
java.util.concurrent.TimeUnit timeUnit)
task - The task to executestartDelay - The delay before the first executionrepeatDelay - The delay between each executiontimeUnit - The time unit of the delayScheduledFuture of the taskpublic void shutdown()
public boolean shutdown(long timeout)
throws java.lang.InterruptedException
timeout - The maximum time to wait for the tasks to finish in millisecondsjava.lang.InterruptedException - If the current thread was interrupted while waitingpublic boolean shutdown(long timeout,
java.util.concurrent.TimeUnit timeUnit)
throws java.lang.InterruptedException
timeout - The maximum time to wait for the tasks to finishtimeUnit - The time unit of the timeoutjava.lang.InterruptedException - If the current thread was interrupted while waiting