public class TaskManager extends Object
This class uses the Logger
named
com.sun.jini.thread.TaskManager
to log information at
the following logging levels:
Level | Description |
---|---|
SEVERE | failure to create a worker thread when no other worker threads exist |
WARNING |
exceptions thrown by TaskManager.Task methods, and failure
to create a worker thread when other worker threads exist
|
Modifier and Type | Class and Description |
---|---|
static interface |
TaskManager.Task
The interface that tasks must implement
|
private class |
TaskManager.TaskThread |
Modifier and Type | Field and Description |
---|---|
protected int |
firstPending
Index of the first pending task; all earlier tasks are active
|
protected float |
loadFactor
Threshold for creating new threads
|
protected static Logger |
logger
Logger
|
protected int |
maxThreads
Maximum number of threads allowed
|
protected List |
roTasks
Read-only view of tasks
|
protected ArrayList |
tasks
Active and pending tasks
|
protected boolean |
terminated
True if manager has been terminated
|
protected List |
threads
Active threads
|
protected long |
timeout
Idle time before a thread should exit
|
Constructor and Description |
---|
TaskManager()
Create a task manager with maxThreads = 10, timeout = 15 seconds,
and loadFactor = 3.0.
|
TaskManager(int maxThreads,
long timeout,
float loadFactor)
Create a task manager.
|
Modifier and Type | Method and Description |
---|---|
void |
add(TaskManager.Task t)
Add a new task.
|
void |
addAll(Collection c)
Add all tasks in a collection, in iterator order.
|
void |
addIfNew(TaskManager.Task t)
Add a new task if it is not equal to (using the equals method)
to any existing active or pending task.
|
int |
getMaxThreads()
Return the maximum number of threads to use on tasks.
|
ArrayList |
getPending()
Return all pending tasks.
|
protected boolean |
needThread()
Return true if a new thread should be created (ignoring maxThreads).
|
boolean |
remove(TaskManager.Task t) |
boolean |
removeIfPending(TaskManager.Task t)
Remove a task if it is pending (not active).
|
private boolean |
removeTask(TaskManager.Task t,
int min)
Remove a task if it has index >= min.
|
private boolean |
runAfter(TaskManager.Task t,
int i)
Returns t.runAfter(i), or false if an exception is thrown.
|
void |
terminate()
Interrupt all threads, and stop processing tasks.
|
protected static final Logger logger
protected final ArrayList tasks
protected int firstPending
protected final List roTasks
protected final List threads
protected final int maxThreads
protected final long timeout
protected final float loadFactor
protected boolean terminated
public TaskManager()
public TaskManager(int maxThreads, long timeout, float loadFactor)
maxThreads
- maximum number of threads to use on taskstimeout
- idle time before a thread exitsloadFactor
- threshold for creating new threads. A new
thread is created if the total number of runnable tasks (both active
and pending) exceeds the number of threads times the loadFactor,
and the maximum number of threads has not been reached.public void addIfNew(TaskManager.Task t)
public void add(TaskManager.Task t)
public void addAll(Collection c)
protected boolean needThread()
private boolean runAfter(TaskManager.Task t, int i)
public boolean removeIfPending(TaskManager.Task t)
public boolean remove(TaskManager.Task t)
private boolean removeTask(TaskManager.Task t, int min)
public void terminate()
public ArrayList getPending()
public int getMaxThreads()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.