Search code examples
mongodbthreadpoolpermgen

Shutdown ScheduledThreadPoolExecutor opened by 3rd party JAR during JVM stop


During JVM stop, few of the thread pool are not getting closed properly. Due to this Perm Gen leak happens as class loader is restricted from being Garbage collected.

These thread pool are opened by 3rd party application (Elasticsearch) and I do not have any direct control over it other than client instance.

client instance do provide methods for shutting down the scheduler and thread pool but this error is not getting rectified. '

Please help. Is there any way we can get instance of 3rd Parties ScheduledThreadPoolExecutor and shutdown it through Java application?


Solution

  • Answer solved by referring these two articles:

    Plumbr tool helped in providing the class loader leak reference and details of thread causing the memory leak.

    Article 1: This article suggested how to find out who created the Thread which is causing the memory leak.

    how to find out who create a thread in java?

    Answer by @Aaron Digulla saved me. Especially 4th and 5th point.

    Article 2: This article suggested how to close the client.

    http://forum.spring.io/forum/spring-projects/data/nosql/118557-mongo-application-fails-to-stop-thread-mongocleaner-with-redeploy-or-restart-tomcat