Package jadex.commons.concurrent
Class LoadManagingExecutionService
- java.lang.Object
-
- jadex.commons.concurrent.LoadManagingExecutionService
-
public class LoadManagingExecutionService extends java.lang.ObjectThis class allows to perform background operations with adjustable CPU utilization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLoadManagingExecutionService.TaskA task info holds a task and meta information.
-
Field Summary
Fields Modifier and Type Field Description protected intconcurrencyThe number of currently running tasks.protected static intCOUNTERThe counter.protected ExecutorexecutorThe executor for performing management operations.protected intlimitA limit for concurrency (to avoid exceeding the timeslice).protected doubleloadThe desired CPU load.protected IThreadPoolpoolThe thread pool.protected longstartThe last start time.protected java.util.SettasksThe tasks to do.protected longtimesliceThe max time slice (in ms).
-
Constructor Summary
Constructors Constructor Description LoadManagingExecutionService(IThreadPool pool)Create an execution service with default settings (timeslice=50).LoadManagingExecutionService(IThreadPool threadpool, long timeslice)Create an execution service with given settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute(IExecutable executable, double priority)Execute a task.static voidmain(java.lang.String[] args)protected voidtaskPerformed(LoadManagingExecutionService.Task task)Called when a task has been performed once.
-
-
-
Field Detail
-
pool
protected IThreadPool pool
The thread pool.
-
load
protected double load
The desired CPU load.
-
timeslice
protected long timeslice
The max time slice (in ms). Only met if single tasks are below this time.
-
tasks
protected java.util.Set tasks
The tasks to do.
-
executor
protected Executor executor
The executor for performing management operations.
-
limit
protected int limit
A limit for concurrency (to avoid exceeding the timeslice).
-
start
protected long start
The last start time.
-
concurrency
protected int concurrency
The number of currently running tasks.
-
COUNTER
protected static int COUNTER
The counter.
-
-
Constructor Detail
-
LoadManagingExecutionService
public LoadManagingExecutionService(IThreadPool pool)
Create an execution service with default settings (timeslice=50).
-
LoadManagingExecutionService
public LoadManagingExecutionService(IThreadPool threadpool, long timeslice)
Create an execution service with given settings.
-
-
Method Detail
-
execute
public void execute(IExecutable executable, double priority)
Execute a task. Triggers the task to be executed in future.- Parameters:
executable- The task to execute.listener- Called when execution has started.
-
taskPerformed
protected void taskPerformed(LoadManagingExecutionService.Task task)
Called when a task has been performed once.
-
main
public static void main(java.lang.String[] args)
-
-