Sharkysoft home

lava.thread
Class TaskParallelizer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--lava.thread.TaskParallelizer
All Implemented Interfaces:
java.lang.Runnable

public class TaskParallelizer
extends java.lang.Thread

Schedules tasks for parallel execution.

Details: TaskParallelizer enqueues tasks to be executed and runs them at a moderated rate, making it reasonable for clients to spawn unlimited numbers of threads without concern for overloading the system.

TaskParallelizers operates on instances of ITask, which are similar to Java Runnable objects, by converting them to Threads before enqueuing them.

Author:
Sharky

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TaskParallelizer(int cl)
          Sets concurrency limit.
 
Method Summary
 void cancel(ITask t)
           
 void enqueue(ITask t, int priority)
          Enqueues task for execution.
 void resumeDispatching()
          Allows new tasks to be started.
 void run()
          Runnable portion of this thread.
 void setExitable(boolean e)
          No summary available.
 void suspendDispatching()
          Prevents new tasks from being started.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TaskParallelizer

public TaskParallelizer(int cl)
Sets concurrency limit.

Details: This constructor sets the concurrency limit for parallel task execution, or the maximum number of simultaneously executing threads that this instance will create. Setting this value lower affords more efficient execution; setting this value higher achieves greater parallelization.

Method Detail

setExitable

public void setExitable(boolean e)
No summary available.

Details: setExitable sets exitable, a flag that indicates whether or not this instance will finish its own thread and stop executing tasks once the waiting queue runs empty.

Parameters:
e - the new value for exitable

run

public void run()
Runnable portion of this thread.
Overrides:
run in class java.lang.Thread

enqueue

public void enqueue(ITask t,
                    int priority)
Enqueues task for execution.

Details: enqueue converts the given ITask (t) into a Thread and adds it to the waiting queue for eventual execution. The position within the queue where the task is inserted depends on the indicated priority (priority) and the priority of already enqueued tasks.

Parameters:
t - the task
priority - the enqueuing priority

cancel

public void cancel(ITask t)

suspendDispatching

public void suspendDispatching()
Prevents new tasks from being started.

Details: suspendDispatching tells this TaskParallelizer that no more enqueued tasks should be started until resumeDispatching is called.


resumeDispatching

public void resumeDispatching()
Allows new tasks to be started.

Details: resumeDispatching tells this TaskParallelizer that it is OK to execute enqueued tasks. This method is typically called some time after suspendDispatching has been called.


Sharkysoft home