qflib 0.98.1

de.qfs.lib.util
Class TaskQueue

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--de.qfs.lib.util.TaskQueue
All Implemented Interfaces:
java.lang.Runnable

public class TaskQueue
extends java.lang.Thread

A TaskQueue is a Thread that executes runnables from a queue.

It is used to handle related tasks, one after the other, from a single background thread. New tasks can be added with addTask and the thread can be terminated with the finish method.

Version:
$Revision: 1.5 $
Author:
Gregor Schmid

Inner Class Summary
static class TaskQueue.UnitTest
          Test cases for the TaskQueue class.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TaskQueue()
          Create a new TaskQueue.
TaskQueue(java.lang.String name)
          Create a new TaskQueue.
 
Method Summary
 void addTask(java.lang.Runnable task)
          Add a task to the TaskQueue.
 void finish(boolean immediately)
          Terminate the operation of the TaskQueue.
 void run()
          Remove tasks from the queue one by one and execute them.
 
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

TaskQueue

public TaskQueue()
Create a new TaskQueue. This does not start the TaskQueue.

TaskQueue

public TaskQueue(java.lang.String name)
Create a new TaskQueue. This does not start the TaskQueue.
Parameters:
name - The thread name for the TaskQueue.
Method Detail

run

public void run()
Remove tasks from the queue one by one and execute them.
Overrides:
run in class java.lang.Thread

finish

public void finish(boolean immediately)
Terminate the operation of the TaskQueue.
Parameters:
immediately - If true, terminate the TaskQueue as soon as possible. Otherwise no more new tasks will be accepted and the thread will be terminated when all pending tasks have been executed.

addTask

public void addTask(java.lang.Runnable task)
Add a task to the TaskQueue. It will be executed as soon as possible.
Parameters:
task - The Runnable to add.

qflib 0.98.1