summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-01-17 12:07:02 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2017-01-17 12:07:02 +0100
commitc33ae916b3247dfc81b07b4f6f7731cc3940fb1b (patch)
tree1deec7a326fbf94ac656a9954dd88da35debb8a6 /container-core
parent45a97f04309c65c64e1ccb2ee1b9db429c4da065 (diff)
Track number of active threads yourself as ThreadPoolExecutor has a cost that is linear to
number of active threads. It also has the threadpool lock while counting. definitely a no,no,no.
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java b/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
index a8f825f0339..f220d9e0027 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/ThreadPoolProvider.java
@@ -9,6 +9,8 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import com.google.inject.Inject;
import com.yahoo.container.protect.ProcessTerminator;
@@ -141,6 +143,8 @@ public class ThreadPoolProvider extends AbstractComponent implements Provider<Ex
private final static class WorkerCompletionTimingThreadPoolExecutor extends ThreadPoolExecutor {
volatile long lastThreadReturnTimeMillis = System.currentTimeMillis();
+ AtomicLong startedCount = new AtomicLong(0);
+ AtomicLong completedCount = new AtomicLong(0);
public WorkerCompletionTimingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
@@ -152,10 +156,22 @@ public class ThreadPoolProvider extends AbstractComponent implements Provider<Ex
}
@Override
+ protected void beforeExecute(Thread t, Runnable r) {
+ super.beforeExecute(t, r);
+ startedCount.incrementAndGet();
+ }
+
+ @Override
protected void afterExecute(Runnable r, Throwable t) {
+ super.afterExecute(r, t);
lastThreadReturnTimeMillis = System.currentTimeMillis();
+ completedCount.decrementAndGet();
}
+ @Override
+ public int getActiveCount() {
+ return (int)(startedCount.get() - completedCount.get());
+ }
}
}