You can send the shutdown command to the shutdown port, both of which can be configured in the root element of the server.xml file of Tomcat.
The steps:
Step 1
Configure CATALINA_HOME / conf / server.xml as follows:
<Server port="8005" shutdown="myShutDownCommand">
The attribute port is optional. If omitted, the default value of 8005 is used.
The shutdown attribute value can be any. This should not be known to others.
Step 2
Make the java program send the shutdown command, myShutDownCommand, using the java.net.Socket class for the shutdown port, 8005.
try { Socket socket = new Socket("localhost", 8005); if (socket.isConnected()) { PrintWriter pw = new PrintWriter(socket.getOutputStream(), true); pw.println("myShutDownCommand");//send shut down command pw.close(); socket.close(); } } catch (Exception e) { e.printStackTrace(); }
Cloud
source share