sim.engine
Class ParallelSequence

java.lang.Object
  extended bysim.engine.Sequence
      extended bysim.engine.ParallelSequence
All Implemented Interfaces:
java.io.Serializable, Steppable

public class ParallelSequence
extends Sequence

Spawns all the sequence elements in parallel on separate threads. This should ONLY be used if you know that all of the elements in the sequence can be executed independently of one another without any race conditions. No synchronization on the model data is done -- you're responsible for that if you need it.

For example, keep in mind that the random number generator is unsynchronized. You should not embed RandomSequences inside a ParallelSequence unless you've set their shouldSynchronize value to true, and elsewhere in your embedded steppables you're synchronizing on the random number generator.

Also, keep in mind that the main thread which fired the ParallelSequence is still holding onto the schedule lock; thus inside the ParallelSequence threads you can't schedule anything (the Schedule is synchronized).

ParallelSequences are lightweight: they reuse the same threads if stepped repeatedly. This means that you must never attach a ParallelSequence inside itself -- that'd be an infinite loop, but it also would create weird thread errors.

Because ParallelSequences are lightweight, their threads are persistent -- even after your main() loop exits! So if you use ParallelSequences, you have to remember to call System.exit(0); to exit your program instead.

While ParallelSequences might LOOK cool, generally speaking the only time you should ever think to use them is if you actually HAVE multiple CPUs on your computer. Otherwise they're almost certainly not the solution to your odd multiple-thread needs.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class sim.engine.Sequence
steps
 
Constructor Summary
ParallelSequence(Steppable[] steps)
           
 
Method Summary
protected  void finalize()
           
 void step(SimState state)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParallelSequence

public ParallelSequence(Steppable[] steps)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

step

public void step(SimState state)
Specified by:
step in interface Steppable
Overrides:
step in class Sequence