Hello,
I am currently running Elasticsearch 5.0.0 and using Java the same java transport client. I have created a dao bean which connects to Elasticsearch such as:
<bean id="searchDAO" class="search.SearchDAO" init-method="init" destroy-method="destroy"/>
In the init method, I have the following:
</>
try {
Settings settings = Settings.builder().put("client.transport.sniff", true)
.put("client.transport.ping_timeout", timeout, TimeUnit.SECONDS).put("cluster.name", this.clusterName)
.build();
TransportClient clientTemp= new PreBuiltTransportClient(settings);
clientTemp.addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(elasticSearchHost), 9300));
client = clientTemp;
}
catch (UnknownHostException e) {
e.printStackTrace();
log.error("Invalid host, unable to connect: " + e.getMessage());
}
</>
and in the destroy method:
</>
if (client == null) {
return;
}
log.info("Shutting down search dao");
client.threadPool().shutdownNow();
try {
client.threadPool().awaitTermination(10, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
log.error("Unable to close the thread pool for elasticsearch");
}
finally {
client.close();
client = null;
}
</>
The issue is that tomcat is unable to shutdown properly due to dangling threads that have been created by the transportclient. I get ugly messages about possible memory leak in catalina.out and I can see through VisualVM that tomcat has active elasticsearch client threads.
SEVERE: The web application [] appears to have started a thread named [elasticsearch[client][transport_client_boss][T#14]] but has failed to stop it. This is very likely to create a memory leak.
Nov 30, 2016 10:32:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [elasticsearch[client][transport_client_boss][T#15]] but has failed to stop it. This is very likely to create a memory leak.
Is there something I am missing while closing connection?