I have a very basic question regarding java application servers running on Eclipse. I would like to execute some code when the admin wishes to stop the server, so I am looking for a function that is called when the "stop" button on the console is pressed by the admin.
The application server is running fine but I would like to clear the state of my database after the server is stopped. The code for my server is given below:
public static void main(String[] args){
try{
while(true){
Socket s=listener.accept();
//do other stuff here
}}
//catch blocks
try{
listener.close();
}
//catch block
System.out.println("Server stopped");
}
However, the statement "server stopped" is never printed on the screen. Could anyone please tell which function is explicitly called when the server is stopped?
Thanks in advance.