Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Nomenclature change: "blocked" -> "waiting"

  • Loading branch information...
commit f0e75374e33e50ef44a8e62049b6cc7fccac66f7 1 parent 6d7faf6
@szegedi szegedi authored
View
46 src/main/java/com/twitter/actors/threadpool/ActorThreadPoolExecutor.java
@@ -18,7 +18,8 @@
/**
* A subclass of {@link ThreadPoolExecutor} that can tell you approximately how
- * many of the actively executing tasks are blocked on a lock or waiting.
+ * many of the actively executing tasks are waiting; see
+ * {@link #getActiveWaitingCount()} for details.
* @author Attila Szegedi
* @version $Id: $
*/
@@ -172,42 +173,33 @@ public ActorThreadPoolExecutor(int corePoolSize,
setThreadFactory(threadFactory);
}
- private class ActorThreadFactory implements ThreadFactory {
- private final ThreadFactory threadFactory;
-
- ActorThreadFactory(ThreadFactory threadFactory) {
- this.threadFactory = threadFactory;
- }
-
- @Override
- public Thread newThread(Runnable r) {
- Thread thread = threadFactory.newThread(r);
- threads.add(thread);
- return thread;
- }
- }
-
@Override
- public void setThreadFactory(ThreadFactory threadFactory) {
- super.setThreadFactory(new ActorThreadFactory(threadFactory));
+ public void setThreadFactory(final ThreadFactory threadFactory) {
+ super.setThreadFactory(new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ Thread thread = threadFactory.newThread(r);
+ threads.add(thread);
+ return thread;
+ }
+ });
}
/**
* Returns the approximate number of threads that are actively
- * executing tasks, but the tasks are blocked.
+ * executing tasks, but the tasks are waiting on a monitor, sleeping,
+ * joining another thread, or being parked.
*
- * @return the number of threads
+ * @return the number of waiting threads
*/
- public int getActiveBlockedCount() {
- int blockedCount = 0;
+ public int getActiveWaitingCount() {
+ int waitingCount = 0;
for(Iterator<Thread> it = threads.iterator(); it.hasNext();) {
Thread thread = it.next();
Thread.State state = thread.getState();
switch(state) {
case WAITING:
- case TIMED_WAITING:
- case BLOCKED: {
- ++blockedCount;
+ case TIMED_WAITING: {
+ ++waitingCount;
break;
}
case TERMINATED: {
@@ -216,8 +208,8 @@ public int getActiveBlockedCount() {
}
}
}
- // Subtract the number of idle threads (as they're all blocked). Number
+ // Subtract the number of idle threads (as they're all waiting). Number
// of idle threads is poolSize - activeCount.
- return Math.max(blockedCount - (getPoolSize() - getActiveCount()), 0);
+ return Math.max(waitingCount - (getPoolSize() - getActiveCount()), 0);
}
}
View
2  src/main/scala/com/twitter/actors/FJTaskScheduler2.scala
@@ -104,7 +104,7 @@ class FJTaskScheduler2 extends Thread with IScheduler {
private var lockupHandler: () => Unit = null
private def numWorkersBlocked = {
- executor.getActiveBlockedCount();
+ executor.getActiveWaitingCount();
}
override def run() {
Please sign in to comment.
Something went wrong with that request. Please try again.