anon.util
Class JobQueue

java.lang.Object
  extended by anon.util.JobQueue

public class JobQueue
extends java.lang.Object

The job queue is meant for threads that are executed very often and do the same things, e.g. updating the screen with different values. At all times, only one job in the queue is executed, and the queue allows no more than two jobs in total (one running and one waiting). If more than two jobs are added, any job in the queue that is currently not running is removed and the new job is added. It will then be executed right after the running job has finished, or it is removed if another job is added meanwhile.

Author:
Rolf Wendolsky

Nested Class Summary
static class JobQueue.Job
          A job that may be added to the job queue.
 
Field Summary
private  boolean m_bInterrupted
           
private  JobQueue.Job m_currentJob
           
private  java.lang.Thread m_currentJobThread
           
private  java.util.Vector m_jobs
           
private  java.util.Vector m_jobThreads
           
private  java.lang.Thread m_threadQueue
           
 
Constructor Summary
JobQueue()
          Creates and starts the job queue.
JobQueue(java.lang.String a_name)
          Creates and starts the job queue.
 
Method Summary
 void addJob(JobQueue.Job a_anonJob)
          Adds a new job to the queue that is run as soon as there are no other running threads left in the queue.
private  void removeJob(JobQueue.Job a_anonJob)
          Must (!!) be called at the end of a job thread to remove this job from the queue and to tell the queue that the job was removed, so that a new job may be started.
 void stop()
          Stops the queue once and for all and interupts all running threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_jobs

private java.util.Vector m_jobs

m_jobThreads

private java.util.Vector m_jobThreads

m_threadQueue

private java.lang.Thread m_threadQueue

m_bInterrupted

private boolean m_bInterrupted

m_currentJob

private JobQueue.Job m_currentJob

m_currentJobThread

private java.lang.Thread m_currentJobThread
Constructor Detail

JobQueue

public JobQueue()
Creates and starts the job queue.


JobQueue

public JobQueue(java.lang.String a_name)
Creates and starts the job queue.

Parameters:
a_name - name of the queue
Method Detail

addJob

public void addJob(JobQueue.Job a_anonJob)
Adds a new job to the queue that is run as soon as there are no other running threads left in the queue. If for a job mayBeSkippedIfDuplicate() returns true, it is skipped if another thread with the same value already is in the queue.

Parameters:
a_anonJob - a Job

stop

public void stop()
Stops the queue once and for all and interupts all running threads. After calling this method, it will not accept any new threads.


removeJob

private void removeJob(JobQueue.Job a_anonJob)
Must (!!) be called at the end of a job thread to remove this job from the queue and to tell the queue that the job was removed, so that a new job may be started.

Parameters:
a_anonJob - a Job to be removed