vanetsim.simulation
Class WorkerThread

java.lang.Object
  extended by java.lang.Thread
      extended by vanetsim.simulation.WorkerThread
All Implemented Interfaces:
java.lang.Runnable

public final class WorkerThread
extends java.lang.Thread

This thread is meant to run parallel with multiple others to gain advantage of multiple CPUs. All simulation tasks are initiated from this class!


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerThread(Region[] ourRegions, int timePerStep)
          The main constructor for the worker thread.
 
Method Summary
 void addChangedRegion(int i)
          Adds a region to the list of changed region (so that it gets updated).
 void run()
          The main method.
 void setBarriers(java.util.concurrent.CyclicBarrier barrierStart, java.util.concurrent.CyclicBarrier barrierDuringWork, java.util.concurrent.CyclicBarrier barrierFinish)
          Set CyclicBarriers for thread synchronization.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WorkerThread

public WorkerThread(Region[] ourRegions,
                    int timePerStep)
The main constructor for the worker thread. Don't use any other constructor inherited from the Thread class as all parameters are essential!

Parameters:
ourRegions - the regions which are assigned to us.
timePerStep - the time in milliseconds for one step
Method Detail

setBarriers

public void setBarriers(java.util.concurrent.CyclicBarrier barrierStart,
                        java.util.concurrent.CyclicBarrier barrierDuringWork,
                        java.util.concurrent.CyclicBarrier barrierFinish)
Set CyclicBarriers for thread synchronization.

Parameters:
barrierStart - the barrier for starting
barrierDuringWork - the barrier after adjusting the speed
barrierFinish - the barrier after completing all tasks

addChangedRegion

public void addChangedRegion(int i)
Adds a region to the list of changed region (so that it gets updated).

Parameters:
i - the number of the region in this thread

run

public void run()
The main method. All simulation is initiated from here!

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread