You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/02/20 11:10:14 UTC
mina-sshd git commit: [SSHD-646] ThreadGroup created in ThreadUtils
is not destroyed and causes memory leak
Repository: mina-sshd
Updated Branches:
refs/heads/master 228263269 -> d3e5d427e
[SSHD-646] ThreadGroup created in ThreadUtils is not destroyed and causes memory leak
* Do not use a separate thread group for each pool
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/d3e5d427
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/d3e5d427
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/d3e5d427
Branch: refs/heads/master
Commit: d3e5d427ea0b48a6dbfc85e9a21cb32dba025b5b
Parents: 2282632
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Sat Feb 20 12:10:55 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Sat Feb 20 12:10:55 2016 +0200
----------------------------------------------------------------------
.../sshd/common/util/threads/ThreadUtils.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d3e5d427/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java b/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java
index d0a25ed..f90ecd1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/util/threads/ThreadUtils.java
@@ -33,6 +33,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.sshd.common.util.logging.AbstractLoggingBean;
+
/**
* Utility class for thread pools.
*
@@ -133,15 +135,15 @@ public final class ThreadUtils {
public static ExecutorService newFixedThreadPool(String poolName, int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads,
- 0L, TimeUnit.MILLISECONDS,
+ 0L, TimeUnit.MILLISECONDS, // TODO make this configurable
new LinkedBlockingQueue<Runnable>(),
new SshdThreadFactory(poolName),
new ThreadPoolExecutor.CallerRunsPolicy());
}
public static ExecutorService newCachedThreadPool(String poolName) {
- return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
- 60L, TimeUnit.SECONDS,
+ return new ThreadPoolExecutor(0, Integer.MAX_VALUE, // TODO make this configurable
+ 60L, TimeUnit.SECONDS, // TODO make this configurable
new SynchronousQueue<Runnable>(),
new SshdThreadFactory(poolName),
new ThreadPoolExecutor.CallerRunsPolicy());
@@ -155,17 +157,15 @@ public final class ThreadUtils {
return newFixedThreadPool(poolName, 1);
}
- public static class SshdThreadFactory implements ThreadFactory {
-
+ public static class SshdThreadFactory extends AbstractLoggingBean implements ThreadFactory {
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
public SshdThreadFactory(String name) {
SecurityManager s = System.getSecurityManager();
- ThreadGroup parentGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
+ group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
String effectiveName = name.replace(' ', '-');
- group = new ThreadGroup(parentGroup, "sshd-" + effectiveName + "-group");
namePrefix = "sshd-" + effectiveName + "-thread-";
}
@@ -178,9 +178,10 @@ public final class ThreadUtils {
if (t.getPriority() != Thread.NORM_PRIORITY) {
t.setPriority(Thread.NORM_PRIORITY);
}
+ if (log.isTraceEnabled()) {
+ log.trace("newThread({})[{}] runnable={}", group, t.getName(), r);
+ }
return t;
}
-
}
-
}