com.jrefinery.report.util
Class Worker

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.jrefinery.report.util.Worker
All Implemented Interfaces:
java.lang.Runnable

public class Worker
extends java.lang.Thread

A simple worker implementation. The worker executes a assigned workload and then sleeps until another workload is set or the worker is killed.

Author:
Thomas Morgner

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Worker()
          Creates a new worker with an default idle timeout of 2 minutes.
Worker(int sleeptime)
          Creates a new worker.
 
Method Summary
 void finish()
          Kills the worker after he completed his work.
 boolean isAvailable()
          Checks, whether this worker has some work to do.
 void run()
          If a workload is set, process it.
 void setWorkload(java.lang.Runnable r)
          Set the next workload for this worker.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, 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

Worker

public Worker(int sleeptime)
Creates a new worker.

Parameters:
sleeptime - the time this worker sleeps until he checks for new work.

Worker

public Worker()
Creates a new worker with an default idle timeout of 2 minutes.

Method Detail

setWorkload

public void setWorkload(java.lang.Runnable r)
Set the next workload for this worker.

Parameters:
r - the next workload for the worker.
Throws:
java.lang.IllegalStateException - if the worker is not idle.

finish

public void finish()
Kills the worker after he completed his work. Awakens the worker if he's sleeping, so that the worker dies without delay.


isAvailable

public boolean isAvailable()
Checks, whether this worker has some work to do.

Returns:
true, if this worker has no more work and is currently sleeping.

run

public void run()
If a workload is set, process it. After the workload is processed, this worker starts to sleep until a new workload is set for the worker or the worker got the finish() request.