在javaweb程序服务器启动后,首次从es查询数据时获取TransportClient都会比较久,后面查询重新获取TransportClient会相对快点,不知道具体是什么原因造成的,如果各位大侠有解决过相同的问题麻烦分享下问题原因及解决方案,非常感谢。
获取TransportClient代码如下:
public static Client getClient() throws UnknownHostException {
Client client = null;
try {
if (StringUtils.isEmpty(ip)) {
ip = def_ip;
}
if (port == 0) {
port = def_port;
}
client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), port));
}
catch (Exception e) {
e.printStackTrace();
}
return client;
}