|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--edu.ull.cgunay.utils.ParallelTask
Parallel analog of an iteration where a given task is executed on
each of the items of a collection concurrently. The
init() method creates threads for all items and the
step() method contains the synchronization algorithm
required to start and end all tasks
concurrently. stop() terminates all threads and
therefore relinquishes resources.
Subsequent calls to step() is mutually exclusive by
ensuring that the the new step does not start until the previous
step is completed.
TODO: Make it more expressive.
Iteration,
Serialized Form| Field Summary | |
Collection |
collection
The collection on which to iterate. |
int |
runcount
Semaphore for threads that are running. |
(package private) Task |
task
Task to be executed at each step by each thread. |
(package private) ThreadGroup |
threads
Group together the threads in order to terminate them at once. |
int |
waitcount
Semaphore for threads that are waiting. |
| Constructor Summary | |
ParallelTask(Collection collection,
Task task)
Set collection and task. |
|
| Method Summary | |
void |
init()
Start a new thread containing the Objective runnable
for each element in the collection. |
void |
reset()
Resets value of runcount to max # of threads. |
void |
step()
Does the following: Wait for all threads to go in wait() (until waitcount = max) Notify all of them, therefore make them execute the task. |
void |
stop()
Terminates all threads, presumably releasing all resources. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public Collection collection
public volatile int waitcount
public volatile int runcount
Task task
ThreadGroup threads
| Constructor Detail |
public ParallelTask(Collection collection,
Task task)
collection - a Collection valuetask - a Task value| Method Detail |
public void reset()
public void init()
Objective runnable
for each element in the collection.
init in interface SimulationObjectivepublic void step()
step in interface Simulationpublic void stop()
stop in interface Simulation
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||