/** * Returns the approximate total number of tasks that have ever been * scheduled for execution. Because the states of tasks and * threads may change dynamically during computation, the returned * value is only an approximation. * * @return the number of tasks */ public long getTaskCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { long n = completedTaskCount; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); n += w.completedTasks; if (w.isLocked()) ++n; } return n + workQueue.size(); } finally { mainLock.unlock(); } }
Worker w = new Worker(firstTask); Thread t = w.thread;
Worker w = new Worker(firstTask); Thread t = w.thread;
Worker w = new Worker(firstTask); Thread t = w.thread;
/** * Returns the approximate total number of tasks that have ever been * scheduled for execution. Because the states of tasks and * threads may change dynamically during computation, the returned * value is only an approximation. * * @return the number of tasks */ public long getTaskCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { long n = completedTaskCount; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); n += w.completedTasks; if (w.isLocked()) ++n; } return n + workQueue.size(); } finally { mainLock.unlock(); } }
/** * Returns the approximate number of threads that are actively * executing tasks. * * @return the number of threads */ public int getActiveCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { int n = 0; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); if (w.isLocked()) ++n; } return n; } finally { mainLock.unlock(); } }
/** * Returns the approximate number of threads that are actively * executing tasks. * * @return the number of threads */ public int getActiveCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { int n = 0; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); if (w.isLocked()) ++n; } return n; } finally { mainLock.unlock(); } }
/** * Returns the approximate total number of tasks that have ever been * scheduled for execution. Because the states of tasks and * threads may change dynamically during computation, the returned * value is only an approximation. * * @return the number of tasks */ public long getTaskCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { long n = completedTaskCount; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); n += w.completedTasks; if (w.isLocked()) ++n; } return n + workQueue.size(); } finally { mainLock.unlock(); } }
/** * Returns the approximate number of threads that are actively * executing tasks. * * @return the number of threads */ public int getActiveCount() { final ReentrantLock mainLock = this.mainLock; mainLock.lock(); try { int n = 0; for (Iterator itr = workers.iterator(); itr.hasNext();) { Worker w = (Worker)itr.next(); if (w.isLocked()) ++n; } return n; } finally { mainLock.unlock(); } }