mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ke Xu (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SSHD-646) ThreadGroup created in ThreadUtils is not destroyed and causes memory leak
Date Tue, 23 Feb 2016 09:41:18 GMT

    [ https://issues.apache.org/jira/browse/SSHD-646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15158624#comment-15158624
] 

Ke Xu commented on SSHD-646:
----------------------------

I did a simple test and more than 1024 threads can be created to main group.
Then I will try 0.14.0 for our application.
Thanks a lot.

> 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)

Mime
View raw message