com.jdon.util.task
类 TaskEngine

java.lang.Object
  继承者 com.jdon.util.task.TaskEngine

public class TaskEngine
extends Object

A TaskEngine object accepts Runnable objects and queues them for execution by worker threads.

Note: the current implementation of this class ignores priority. This may be changed in the future, however. this is s simple task/job engine, more power see Quartz or JMS usage:

 TaskEngine taskEngine = new TaskEngine();
 MyTask myTask = new MyTask();
 engine.addTask(myTask, Thread.NORM_PRIORITY);
 
MyTask must implements Runnable of Thread.


方法摘要
static void addTask(Runnable r)
          Adds a task to the task queue with normal priority.
static void addTask(Runnable task, int priority)
          Adds a task to the task queue.
static TimerTask scheduleTask(Runnable task, int priority, long delay, long period)
          Schedules a task to periodically run.
static TimerTask scheduleTask(Runnable task, long delay, long period)
          Schedules a task to periodically run.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

方法详细信息

addTask

public static void addTask(Runnable r)
Adds a task to the task queue with normal priority. The task will be executed immediately provided there is a free worker thread to execute it. Otherwise, it will execute as soon as a worker thread becomes available.


addTask

public static void addTask(Runnable task,
                           int priority)
Adds a task to the task queue. The task will be executed immediately provided there is a free worker thread to execute it. Otherwise, it will execute as soon as a worker thread becomes available.

The priority of the task can be specified and must be one of the following values:

参数:
task - the task to execute

scheduleTask

public static TimerTask scheduleTask(Runnable task,
                                     long delay,
                                     long period)
Schedules a task to periodically run. This is useful for tasks such as updating search indexes, deleting old data at periodic intervals, etc.

参数:
task - task to be scheduled.
delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.
返回:
a TimerTask object which can be used to track executions of the task and to cancel subsequent executions.

scheduleTask

public static TimerTask scheduleTask(Runnable task,
                                     int priority,
                                     long delay,
                                     long period)
Schedules a task to periodically run. This is useful for tasks such as updating search indexes, deleting old data at periodic intervals, etc.

参数:
task - task to be scheduled.
priority - the priority the periodic task should run at.
delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.
返回:
a TimerTask object which can be used to track executions of the task and to cancel subsequent executions.


Copyright © 2013. All Rights Reserved.