[
https://issues.apache.org/jira/browse/SSHD-646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15158498#comment-15158498
]
Ke Xu commented on SSHD-646:
----------------------------
Thanks for the response.
In our app, we dont't have the security manager and the current thread's group
is the main group. It can hold only 1024 threads. (java.lang.Thread[1024]).
In the meanwhile, we need to make a lot of ssh connections (huge numbers larger
than 1024).
Seems the solution in 0.14.0 not suffient?
For previous version, e.g. 0.10.0,
the pool is created with java.util.concurrent.Executors, no thread group is
created.
Will the old version 0.10.0 solve our problem?
> ThreadGroup created in ThreadUtils is not destroyed and causes memory leak
> --------------------------------------------------------------------------
>
> Key: SSHD-646
> URL: https://issues.apache.org/jira/browse/SSHD-646
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 1.0.0
> Environment: linux
> Reporter: Ke Xu
> Assignee: Goldstein Lyor
> Fix For: 1.2.0
>
> Original Estimate: 8h
> Remaining Estimate: 8h
>
> ===============
> Problem description
> ===============
> In our application, we found that more than 250M memory were occupied by
> around 700,000 ThreadGroup objects (whose names are SshClient-nio2, timer,
> ClientInputStreamPump). The Threads contained in these ThreadGroups and their
> sub groups were all null.
> ===============
> Analysis
> ===============
> In ThreadUtils class there is an inner class named SshdThreadFactory. Inside
> this class, it will create a ThreadGroup and attach it to the parent
> Threadgroup:
> group = new ThreadGroup(parentGroup, "sshd-" + effectiveName + "-group");
> However, the destroy() method of the ThreadGroup object is never explicitely
> called when relevent resources are closed.
> According to ThreadGroup API, when a ThreadGroup is created with parent
> ThreadGroup specified, a reference to this child ThreadGroup is created in
> the parent. The destroy() method is the only way to make the parent to remove
> this reference.
> Thus in case the parent ThreadGroup is main, and there is a lot of
> ThreadGroup created, the ThreadGoup objects are not collected by the system
> until program exits. It will eventually occupy a lot of memory.
> ===============
> Suggested solution
> ===============
> A suggested solution is to mark the ThreadGroup object as daemon after it is
> created in SshdThreadFactory, e.g.:
> group = new ThreadGroup(parentGroup, "sshd-" + effectiveName +
> "-group");
> group.setDaemon(true);
> According to API, when a ThreadGroup is marked as daemon, it is automatically
> destroyed when its last thread is stopped or its last thread group is
> destroyed.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)