ThreadLocal,memory leak, Glassfish4.1

  • I use elasticsearch transportclient in my java web application. But when I undeploy the application , glassfish logs show about 20 messages , the content is this:
[my application] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@5e5903f5]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@273d03c7]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.]]   

my code is this:

public static void destroyInstance(TransportClient client) {
        if (client != null) {
            try {
                client.threadPool().shutdownNow();
                client.threadPool().close();
                client.close();
                client = null;
                Logger.getLogger("TransportClient destroyed");
            } catch (Exception ex) {
                Logger.getLogger(ESClientManager.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }  

I initialize the client in the contextInitialized , use singleton and destroy the Instancein the contextDestroyed.
I also get one Exception :

[2017-06-21T09:11:28.161+0800] [glassfish 4.1] [SEVERE] [] [javax.enterprise.web] [tid: _ThreadID=48 _ThreadName=admin-listener(5)] [timeMillis: 1498007488161] [levelValue: 1000] [[
  WebModule[/service_generic_log]Exception sending context destroyed event to listener instance of class v2.service.generic_log.LogContextListener
java.lang.IllegalStateException: thread was not started
	at io.netty.util.concurrent.GlobalEventExecutor.awaitInactivity(GlobalEventExecutor.java:197)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.close(PreBuiltTransportClient.java:134)
	at v2.service.generic_log.ESClientManager.destroyInstance(ESClientManager.java:60)
	at v2.service.generic_log.LogContextListener.contextDestroyed(LogContextListener.java:44)
	at org.apache.catalina.core.StandardContext.contextListenerStop(StandardContext.java:5480)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:6146)
	at com.sun.enterprise.web.WebModule.stop(WebModule.java:720)
	at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1172)
	at com.sun.enterprise.web.WebContainer.unloadWebModule(WebContainer.java:2439)
	at com.sun.enterprise.web.WebContainer.unloadWebModule(WebContainer.java:2394)
	at com.sun.enterprise.web.WebApplication.stop(WebApplication.java:190)
	at org.glassfish.internal.data.EngineRef.stop(EngineRef.java:161)
	at org.glassfish.internal.data.ModuleInfo.stop(ModuleInfo.java:324)
	at org.glassfish.internal.data.ApplicationInfo.stop(ApplicationInfo.java:380)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.unload(ApplicationLifecycle.java:1059)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.undeploy(ApplicationLifecycle.java:1099)
	at org.glassfish.deployment.admin.UndeployCommand.execute(UndeployCommand.java:412)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:360)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:360)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
	at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
	at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
	at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
	at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
	at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
	at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
	at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
	at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
	at org.glassfish.grizzly.portunif.PUFilter.handleRead(PUFilter.java:231)
	at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
	at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(Defaulorg.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
	at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
	at java.lang.Thread.run(Thread.java:745)
]]
  • Elasticsearch version:
    5.4.0
  • JVM version (java -version):
    openjdk version "1.8.0_111"
    OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-2ubuntu0.16.04.2-b14)
    OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
    I would appreciate it if you could give me a hand. Thanks a lot !

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.