Elasticsearch Client只初始化一次,但是项目运行到一定时间回报tomcat内存溢出
Elasticsearch | 作者 sskiand | 发布于2017年08月11日 | 阅读数:9506
代码段:
public static Client init() {
try {
Properties properties = CommonUtil.readConfig("elasticsearch.properties");
String clusterName = properties.getProperty("clusterName").trim(); // 集群名称
String url = properties.getProperty("hosts").trim(); // 访问地址
String[] location = url.split(",");
Settings settings = Settings.builder().put("cluster.name", clusterName).build();
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(location[0]), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(location[1]),9300));
properties = CommonUtil.readConfig("sort/sort.properties");
distanceWords = properties.getProperty("distance").trim();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}
public ElasticUtil() {
try {
client = init();
} catch (Exception e) {
e.printStackTrace();
}
adminClient = client.admin().indices();
}
异常日志:
10-Aug-2017 17:41:36.840 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [elasticsearch[_client_][generic][T#4]] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.LinkedTransferQueue.awaitMatch(LinkedTransferQueue.java:737)
java.util.concurrent.LinkedTransferQueue.xfer(LinkedTransferQueue.java:647)
java.util.concurrent.LinkedTransferQueue.take(LinkedTransferQueue.java:1269)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
10-Aug-2017 17:41:36.841 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@740a4cbe]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@550d63d3]) 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.
public static Client init() {
try {
Properties properties = CommonUtil.readConfig("elasticsearch.properties");
String clusterName = properties.getProperty("clusterName").trim(); // 集群名称
String url = properties.getProperty("hosts").trim(); // 访问地址
String[] location = url.split(",");
Settings settings = Settings.builder().put("cluster.name", clusterName).build();
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(location[0]), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(location[1]),9300));
properties = CommonUtil.readConfig("sort/sort.properties");
distanceWords = properties.getProperty("distance").trim();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}
public ElasticUtil() {
try {
client = init();
} catch (Exception e) {
e.printStackTrace();
}
adminClient = client.admin().indices();
}
异常日志:
10-Aug-2017 17:41:36.840 警告 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [elasticsearch[_client_][generic][T#4]] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.LinkedTransferQueue.awaitMatch(LinkedTransferQueue.java:737)
java.util.concurrent.LinkedTransferQueue.xfer(LinkedTransferQueue.java:647)
java.util.concurrent.LinkedTransferQueue.take(LinkedTransferQueue.java:1269)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
10-Aug-2017 17:41:36.841 严重 [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@740a4cbe]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@550d63d3]) 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.
1 个回复
匿名用户
赞同来自: