sam.toolkit
Class Workshop
java.lang.Object
|
+--sam.toolkit.Workshop
- public class Workshop
- extends java.lang.Object
This class implements a multi-threading workshop.
It basically allows to dispatch any number of
Runnable
tasks accross a fixed
number of working Thread>/CODE>s.
Constructor Summary |
Workshop(int numberOfWorkers)
|
Method Summary |
static void |
main(java.lang.String[] args)
Sample test code. |
int |
numberOfWorkers()
|
void |
startAsSoonAsPossible(java.lang.Runnable task)
Starts specified task as soon as a worker is ready to run it. |
void |
waitForCompletion()
Waits for all currently running tasks be completed,
which excludes any pending and not currently running task. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Workshop
public Workshop(int numberOfWorkers)
- Parameters:
numberOfWorkers
- the fixed maximum number of simultaneous active tasks
numberOfWorkers
public int numberOfWorkers()
- Returns:
- the maximum number of simultaneous active tasks
startAsSoonAsPossible
public void startAsSoonAsPossible(java.lang.Runnable task)
throws Workshop.IllegalWorkerStateException
- Starts specified task as soon as a worker is ready to run it.
Note that this turns to a blocking call whenever no
such worker exists, until one active threads completes its actual job.
Workshop.IllegalWorkerStateException
waitForCompletion
public void waitForCompletion()
throws Workshop.IllegalWorkerStateException
- Waits for all currently running tasks be completed,
which excludes any pending and not currently running task.
Thus this method should only be called inside the same thread
as that which calls
startAsSoonAsPossible
(which is a blocking call). In this way, calling waitForCompletion
actually leads to waiting for all pending tasks be completed.
Workshop.IllegalWorkerStateException
main
public static void main(java.lang.String[] args)
throws java.lang.Throwable
- Sample test code.
java.lang.Throwable