/** * Executes a task on behalf of this thread pool. If all threads are currently * busy, this method call blocks until a thread gets idle again which is when * the call returns immediately. * @param task * a <code>Runnable</code> to execute. */ public synchronized void execute(WorkerTask task) { while (true) { for (int i=0; i<taskManagers.size(); i++) { TaskManager tm = (TaskManager) taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); } if (tm.isIdle()) { tm.execute(task); return; } } try { wait(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } }
/** * Tries to execute a task on behalf of this thread pool. If all threads are * currently busy, this method returns <code>false</code>. Otherwise the task * is executed in background. * @param task * a <code>Runnable</code> to execute. * @return * <code>true</code> if the task is executing. * @since 1.6 */ public synchronized boolean tryToExecute(WorkerTask task) { for (int i=0; i<taskManagers.size(); i++) { TaskManager tm = (TaskManager) taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); } if (tm.isIdle()) { tm.execute(task); return true; } } return false; }
for (int i=0; i<taskManagers.size(); i++) { TaskManager tm = taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); taskManagers.set(i, tm);
for (int i = 0; i < taskManagers.size(); i++) { TaskManager tm = taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); taskManagers.set(i, tm);
/** * Tries to execute a task on behalf of this thread pool. If all threads are * currently busy, this method returns <code>false</code>. Otherwise the task * is executed in background. * @param task * a <code>Runnable</code> to execute. * @return * <code>true</code> if the task is executing. * @since 1.6 */ public boolean tryToExecute(WorkerTask task) { for (int i=0; i<taskManagers.size(); i++) { TaskManager tm = taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); } if (tm.isIdle()) { try { tm.execute(task); return true; } catch (IllegalStateException isex) { // ignore } } } return false; }
/** * Tries to execute a task on behalf of this thread pool. If all threads are * currently busy, this method returns <code>false</code>. Otherwise the task * is executed in background. * * @param task * a <code>Runnable</code> to execute. * * @return <code>true</code> if the task is executing. * @since 1.6 */ public boolean tryToExecute(WorkerTask task) { for (int i = 0; i < taskManagers.size(); i++) { TaskManager tm = taskManagers.get(i); if ((respawnThreads) && (!tm.isAlive())) { tm = new TaskManager(getTaskManagerName(name, i)); } if (tm.isIdle()) { try { tm.execute(task); return true; } catch (IllegalStateException isex) { // ignore } } } return false; }