在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;
}
vi /etc/profile
source /etc/profile
Java -version
Vi server.xml
vi /etc/sysconfig/iptables
/etc/init.d/iptables restart
linux tomcat shutdown命令杀不死进程问题
解决方案三:
基本原理为启动tomcat时记录启动tomcat的进程id(pid),关闭时强制杀死该进程
第一步 :vim修改tomcat下bin/catalina.sh文件,添加点东西,主要是记录tomcat的pid,如下:
#设置记录CATALINA_PID。
#该设置会在启动时候bin下新建一个CATALINA_PID文件
#关闭时候从CATALINA_PID文件找到pid,kill。。。同时删除CATALINA_PID文件
if [ -z "$CATALINA_PID" ]; then
CATALINA_PID=$PRGDIR/CATALINA_PID
Fi
第二步 vim tomcat的shutdown.sh文件,在最后一行加上-force:
修改jar包日志
jar cvf elasticsearch-2.4.0.jar config META-INF org es-build.properties
导出war包
<?xml version="1.0" encoding="UTF-8"?>
<target name="clean" description="delete dist directory">
<delete dir="${classes}" />
<delete dir="${rel.dir}" />
</target>
<target name="compile" depends="clean" description="create ${classes} path, compile source and put binary file in ${classes} path">
<mkdir dir="${classes}" />
<javac destdir="${classes}" target="1.7" debug="true" deprecation="false" optimize="false"
failonerror="true" encoding="UTF-8">
<src path="${src.dir}" />
<classpath refid="lib_classpath" />
</javac>
</target>
<target name="copyXml" description="put configuration in the ${classes} path">
<copy todir="${classes}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<!--
<target name="copyMetaInf" description="put meta-inf context.xml in the ${dist} path">
<copy todir="${dist}/META-INF">
<fileset dir="WebContent/META-INF">
<include name="context.xml" />
</fileset>
</copy>
</target>
-->
<target name="copyProperties" description="put properties in the ${dist} path">
<copy todir="${classes}">
<fileset dir="${src.dir}">
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<target name="war" depends="compile,copyXml" description="generate war" >
<war destfile="${dist}/${project.name}.war" webxml="WebContent/WEB-INF/web.xml" duplicate="preserve">
<fileset dir="WebContent">
<!--exclude name="WEB-INF/lib/*.jar" /-->
<exclude name="WEB-INF/web.xml" />
<!--exclude name="META-INF/*" /-->
</fileset>
<lib dir="${build.lib.dir}">
</lib>
<classes dir="${classes}"/>
</war>
<mkdir dir="${rel.dir}" />
<copy file="${dist}/${project.name}.war" todir="${rel.dir}"/>
</target>