title: function called when java application server is stopped using GUI on eclipse
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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");
    }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks in advance.</p>