# Worker
Date: 2020-11-15

de.hems.trafficsim

## Class Worker

- java.lang.Object
- - java.lang.Thread
  - - de.hems.trafficsim.Worker

All Implemented Interfaces:
  java.lang.Runnable

    public class Worker
    extends java.lang.Thread

Calculation thread, which runs the simulation itself and also updates the view with a set rate.

### Nested Class Summary

### Nested classes/interfaces inherited from class java.lang.Thread

`java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

### Field Summary

Fields
`protected int` `frameskip` Amount of simulation steps between two frames in the view.
`protected MainActivity` `gui` the MainActivity of the gui
`protected Renderer` `renderer` the Renderer drawing the Track
`protected boolean` `stop` Stop flag, indicating that the worker shall stop
`protected Track` `track` the track to simulate

### Fields inherited from class java.lang.Thread

`MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

### Constructor Summary

Constructors
Constructor and Description
`Worker(Track track, MainActivity gui, Renderer renderer, int frameskip)` Construct a new worker.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `run()` Method which is automatically executed when the thread is started.
`void` `setFrameskip(int frames)` Updates the amount of simulation steps between to view frames.
`void` `setStop(boolean stop)` Sets a flag that causes the worker to stop.

### Methods inherited from class java.lang.Thread

`activeCount, checkAccess, clone, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### track

    protected Track track

the track to simulate

#### stop

    protected boolean stop

Stop flag, indicating that the worker shall stop

#### gui

    protected MainActivity gui

the MainActivity of the gui

#### renderer

    protected Renderer renderer

the Renderer drawing the Track

#### frameskip

    protected int frameskip

Amount of simulation steps between two frames in the view. Zero means that every simulation step is drawn.

### Constructor Detail

#### Worker

    public Worker(Track track,
                  MainActivity gui,
                  Renderer renderer,
                  int frameskip)

Construct a new worker.

Parameters:
  `track` - the track to simulate
  `gui` - the MainActivity of the gui
  `renderer` - the Renderer drawing the Track
  `frameskip` - Amount of simulation steps between two frames in the view. Zero means that every simulation step is drawn

### Method Detail

#### setStop

    public void setStop(boolean stop)

Sets a flag that causes the worker to stop.

Parameters:
  `stop` - flag whether the thread shall stop

#### setFrameskip

    public void setFrameskip(int frames)

Updates the amount of simulation steps between to view frames.

Parameters:
  `frames` - amount of steps

#### run

    public void run()

Method which is automatically executed when the thread is started. It alternates between updating the simulation and drawing a new frame in the view.

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