Methods Summary |
---|
private void | createThread()
if (idle < 1) {
synchronized(threadList) {
if (jobList.size() > 0 && currThreds < minThreads) {
ExecutorThread et = new ExecutorThread();
et.start();
threadList[currThreds++] = et;
//System.out.println("jsl-ThreadService: create new thread: "+currThreds);
}
}
}
|
public void | removeAll()
stateCheck();
final Object[] jobs;
synchronized(jobList) {
jobs = jobList.toArray();
jobList.clear();
}
final int len = jobs.length;
for (int i=0; i<len ; i++) {
final Object o = jobs[i];
if (o!= null && o instanceof Task) ((Task)o).cancel();
}
|
public java.lang.Runnable | removeTask(java.lang.Runnable task)
stateCheck();
Runnable removed = null;
synchronized(jobList) {
int lg = jobList.indexOf(task);
if (lg >= 0) {
removed = (Runnable)jobList.remove(lg);
}
}
if (removed != null && removed instanceof Task)
((Task) removed).cancel();
return removed;
|
private void | stateCheck()
if (terminated) {
throw new IllegalStateException("The thread service has been terminated.");
}
|
public void | submitTask(com.sun.jmx.snmp.tasks.Task task)Submit a task to be executed.
Once a task is submitted, it is guaranteed that either
{@link com.sun.jmx.snmp.tasks.Task#run() task.run()} or
{@link com.sun.jmx.snmp.tasks.Task#cancel() task.cancel()} will be called.
This implementation of TaskServer uses a thread pool to execute
the submitted tasks.
submitTask((Runnable)task);
|
public void | submitTask(java.lang.Runnable task)Submit a task to be executed.
This implementation of TaskServer uses a thread pool to execute
the submitted tasks.
stateCheck();
if (task == null) {
throw new IllegalArgumentException("No task specified.");
}
synchronized(jobList) {
jobList.add(jobList.size(), task);
//System.out.println("jsl-ThreadService: added job "+addedJobs++);
jobList.notify();
}
createThread();
|
public void | terminate()
if (terminated == true) {
return;
}
terminated = true;
synchronized(jobList) {
jobList.notifyAll();
}
removeAll();
for (int i=0; i<currThreds; i++) {
try {
threadList[i].interrupt();
} catch (Exception e) {
// TODO
}
}
threadList = null;
|