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
|
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<TaskManager.Task> |
tasks
Active and pending tasks
|
protected boolean |
terminated
True if manager has been terminated
|
protected List<com.sun.jini.thread.TaskManager.TaskThread> |
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.
|
TaskManager(int maxThreads,
long timeout,
float loadFactor,
String threadName,
int retriesOnIdle) |
TaskManager(int maxThreads,
long timeout,
float loadFactor,
String threadName,
int retriesOnIdle,
int threadPriority) |
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.
|
List<TaskManager.Task> |
getPending()
Return all pending tasks.
|
String |
getThreadName() |
int |
getTotalTasks()
Returns the total number of tasks to be executed and currently executing.
|
boolean |
isTerminated() |
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).
|
void |
setThreadName(String threadName) |
void |
terminate()
Interrupt all threads, and stop processing tasks.
|
protected static final Logger logger
protected final ArrayList<TaskManager.Task> tasks
protected int firstPending
protected final List roTasks
protected final List<com.sun.jini.thread.TaskManager.TaskThread> 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 TaskManager(int maxThreads, long timeout, float loadFactor, String threadName, int retriesOnIdle)
public TaskManager(int maxThreads, long timeout, float loadFactor, String threadName, int retriesOnIdle, int threadPriority)
public void addIfNew(TaskManager.Task t)
public void add(TaskManager.Task t)
public void setThreadName(String threadName)
public String getThreadName()
public void addAll(Collection c)
protected boolean needThread()
public boolean removeIfPending(TaskManager.Task t)
public boolean remove(TaskManager.Task t)
public void terminate()
public boolean isTerminated()
public List<TaskManager.Task> getPending()
public int getTotalTasks()
public int getMaxThreads()
Copyright © GigaSpaces.