org.jfree.report.util

Class Worker


public final class Worker
extends 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

Constructor Summary

Worker()
Creates a new worker.

Method Summary

void
finish()
Kills the worker after he completed his work.
WorkerPool
getWorkerPool()
Returns the worker's assigned pool.
Runnable
getWorkload()
Returns the workload object.
boolean
isAvailable()
Checks, whether this worker has some work to do.
boolean
isFinish()
Checks whether this worker has received the signal to finish and die.
void
run()
If a workload is set, process it.
void
setWorkerPool(WorkerPool workerPool)
Defines the worker's assigned pool.
void
setWorkload(Runnable r)
Set the next workload for this worker.

Constructor Details

Worker

public Worker()
Creates a new worker.
Parameters:

Method Details

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.

getWorkerPool

public WorkerPool getWorkerPool()
Returns the worker's assigned pool.
Returns:
the worker pool (or null, if the worker is not assigned to a pool).

getWorkload

public Runnable getWorkload()
Returns the workload object.
Returns:
the runnable executed by this worker thread.

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.

isFinish

public boolean isFinish()
Checks whether this worker has received the signal to finish and die.
Returns:
true, if the worker should finish the work and end the thread.

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.

setWorkerPool

public void setWorkerPool(WorkerPool workerPool)
Defines the worker's assigned pool.
Parameters:
workerPool - the worker pool (or null, if the worker is not assigned to a pool).

setWorkload

public void setWorkload(Runnable r)
Set the next workload for this worker.
Parameters:
r - the next workload for the worker.