public Runnable removeTask(Runnable task) { stateCheck(); Runnable removed = null; synchronized(jobList) { int lg = jobList.indexOf(task); if (lg >= 0) { removed = jobList.remove(lg); } } if (removed != null && removed instanceof Task) ((Task) removed).cancel(); return removed; }
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(); } }
private ThreadPool createThreadPoolMock(String threadPoolName, int callTimes) { ThreadPool mock = createMock(ThreadPool.class); mock.submit( anyObject(Task.class), eq(threadPoolName)); expectLastCall().andReturn(createMock(Future.class)).times(callTimes); replay(mock); return mock; }
/** * 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. * @param task The task to be executed. * @exception IllegalArgumentException if the submitted task is null. **/ public void submitTask(Task task) throws IllegalArgumentException { submitTask((Runnable)task); }