com.dvt.app.threadworks
Class TaskManager

java.lang.Object
  |
  +--com.dvt.app.threadworks.TaskManager

public class TaskManager
extends java.lang.Object

Runs any asynchronous, runnable tasks.

A TaskManager allows you to dispatch any task(s) to run asynchronously. TaskManager will optionally generate a completion event when the task is completed. TaskManager can also dispatch tasks for you dependent upon the successful completion of other tasks. TaskManager will log any runtime errors encountered. Dispatchable tasks are any class that implements java.lang.Runnable.

TaskManager will optionally terminate a run-away task that runs past a configurable time threshold. TaskManager also generates log information at a configurable interval to assist you with tuning for large, high-volume applications. The default TaskManager configuration will work for most applications.

It is recommended, but not required, that dispatched tasks implement Describable (@see com.dvt.app.common.Describable) as well as Runnable. Describables are capable of producing textual descriptions of themselves. If the task excepts or exceeds its maximum allowed run time, TaskManager will log the probleem. If the task is Describable, TaskManager will log the tasks description as well. This facilitates support.

Typically, TaskManagers are defined as static variables and are shared throughout an application. TaskManager is thread-safe. Examples of TaskManager definitions follow:

       private static TaskManager _manager = new TaskManager(5);
 
       DefaultTaskManagerEnvironment env = new DefaultTaskManagerEnvironment();
       TaskManager manager = new TaskManager(env);
 
       DefaultTaskManagerEnvironment env = new DefaultTaskManagerEnvironment(
           new OutputStreamLogger(),
           20,
           Thread.NORM_PRIORITY,
           4000,
           DefaultTaskManagerEnvironment.DEFAULT_DIAGNOSTIC_REPORTING_INTERVAL,
           DefaultTaskManagerEnvironment.DEFAULT_LOG_LABEL);
      _manager = new TaskManager(env);
 

Tasks are dispatched by calling one of the "run" methods. Examples of use follow:

       manager.run(logTask);
       manager.run(customerLookUpTask, lookupCompletionListener);
 

Copyright: Delta Vortex Technologies, 2001.


Constructor Summary
TaskManager(int maxNbrConcurrentTasks)
          Starts a TaskManager with a given number of threads.
TaskManager(Logger log, int maxNbrConcurrentTasks, int threadPriority, long maxTaskTimeAllowedInMillis, long diagnosticReportingIntervalInMillis, java.lang.String logLabel)
          Starts a TaskManager with the given environment information.
TaskManager(java.lang.String propertiesFileName)
          Starts a TaskManager using environment defined in a properties file.
TaskManager(TaskManagerEnvironment env)
          Starts a TaskManager with the given environment information.
 
Method Summary
 java.lang.String getLabel()
          Gets labeling information for TaskManager log.
 void logDiagnostics()
          Logs performance statistics to the logger provided on construction.
 void run(java.util.Collection runnableTasks)
          Runs a group of asynchronous tasks.
 void run(java.util.Collection runnableTasks, CompletionEventListener listener)
          Runs a group of asynchronous tasks.
 void run(java.lang.Runnable task)
          Runs an asynchronous task.
 void run(java.lang.Runnable[] task)
          Runs a group of asynchronous tasks.
 void run(java.lang.Runnable[] task, CompletionEventListener listener)
          Runs an asynchronous task.
 void run(java.lang.Runnable[] dependentTasks, java.lang.Runnable[] successorTasks, CompletionEventListener listener)
          Runs one or more successor tasks after all dependent tasks are complete.
 void run(java.lang.Runnable task, CompletionEventListener listener)
          Runs an asynchronous task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskManager

public TaskManager(int maxNbrConcurrentTasks)
            throws java.io.IOException,
                   ThreadWorksException
Starts a TaskManager with a given number of threads. All other parts of the environment default. See JavaDoc for DefaultTaskManagerEnvironment for details about default settings.
Parameters:
Maximum - Number of Concurrent Tasks
See Also:
DefaultTaskManagerEnvironment

TaskManager

public TaskManager(TaskManagerEnvironment env)
            throws ThreadWorksException
Starts a TaskManager with the given environment information.
Parameters:
Environment -  

TaskManager

public TaskManager(java.lang.String propertiesFileName)
            throws java.io.IOException,
                   ThreadWorksException
Starts a TaskManager using environment defined in a properties file. This properties file must be in the classpath.
Parameters:
Filename -  

TaskManager

public TaskManager(Logger log,
                   int maxNbrConcurrentTasks,
                   int threadPriority,
                   long maxTaskTimeAllowedInMillis,
                   long diagnosticReportingIntervalInMillis,
                   java.lang.String logLabel)
            throws ThreadWorksException
Starts a TaskManager with the given environment information.
Parameters:
Message - logger
Maximum - Number of Concurrent Tasks
Thread - Priority
Maximum - time in millis allowed on a single task
Time - interval in which to report TaskManager diagnostics
Label - used in logging to identify this particular TaskManager
Method Detail

logDiagnostics

public void logDiagnostics()
Logs performance statistics to the logger provided on construction.

run

public void run(java.lang.Runnable task)
         throws ThreadWorksException
Runs an asynchronous task.

run

public void run(java.lang.Runnable[] task)
         throws ThreadWorksException
Runs a group of asynchronous tasks.

run

public void run(java.util.Collection runnableTasks)
         throws ThreadWorksException
Runs a group of asynchronous tasks. All objects in the collection must be runnable.

run

public void run(java.util.Collection runnableTasks,
                CompletionEventListener listener)
         throws ThreadWorksException
Runs a group of asynchronous tasks. All objects in the collection must be runnable. Generates a completion event afterwords, which is posted to the CompletionEventListener provided.

run

public void run(java.lang.Runnable task,
                CompletionEventListener listener)
         throws ThreadWorksException
Runs an asynchronous task. Generates a completion event afterwords and posts it to a CompletionEventListener provided.

run

public void run(java.lang.Runnable[] task,
                CompletionEventListener listener)
         throws ThreadWorksException
Runs an asynchronous task. Generates a completion event afterwords and posts it to the CompletionEventListener provided.

run

public void run(java.lang.Runnable[] dependentTasks,
                java.lang.Runnable[] successorTasks,
                CompletionEventListener listener)
         throws ThreadWorksException
Runs one or more successor tasks after all dependent tasks are complete. If an error is generated by one of the dependent tasks, the successor tasks will not be started. When all dependent and successor tasks are complete, a completion notification is sent to the listener provided.

getLabel

public java.lang.String getLabel()
Gets labeling information for TaskManager log.


Copyright © 2001 Delta Vortex Technologies, Inc. All Rights Reserved.