Worker Task model element
WorkerTask defines a piece of code that can be run in a thread separate to the EJS model
Usage
To add a worker task code to your model, drag the icon element to the list of your model elements
and enter the code to run.
The element implements the following basic methods:
- boolean startAndReturn(): Runs the code sequentially in a separate thread.
- long getExecutionTime(): returns the time (in milliseconds) of the last execution. -1 if the region has never been run.
- void resetInitialTime(): resets the initial time to measure the execution time. (The initial time is reset automatically when the startAndReturn method is called.)
- boolean isAlive(): whether the code is currently running.
- void release(): releases the thread created for the element.(The element is released automatically when the simulation quits.)
Example of use
workerTask.startAndReturn(); // runs the task code in a separate thread
_println ("The worker task code took "+workerTask.getExecutionTime()+" ms to run.");