Advertisement
Guest User

Long Shutdown Sequence in Tomcat

a guest
Mar 14th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package com.company.status;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. import org.apache.log4j.Logger;
  13.  
  14. public class StatusServlet extends HttpServlet {
  15.    
  16.     private static Logger log = Logger.getLogger(StatusServlet.class.getName());
  17.    
  18.     public void init() throws ServletException {
  19.         log.info("StatusServlet.init()");
  20.     }
  21.  
  22.     public void doGet(HttpServletRequest req, HttpServletResponse res)
  23.             throws ServletException, IOException {
  24.  
  25.         res.setContentType("text/html");
  26.         PrintWriter w = res.getWriter();
  27.         w.println("<html><head><title>Status Monitor</title></head>");
  28.         w.println("<body><h1>Status monitoring is ONLINE.</h1></body></html>");
  29.  
  30.         w.flush(); // Commits the response
  31.         w.close();
  32.     }
  33.  
  34.     public void doPost(HttpServletRequest req, HttpServletResponse res)
  35.             throws ServletException, IOException {
  36.         // ...
  37.     }
  38.  
  39.     public void destroy() {
  40.         log.info("Entering StatusServlet.destroy()");
  41.         try {
  42.             log.info("Simulating long shutdown sequence.");
  43.             TimeUnit.MINUTES.sleep(5);
  44.             log.info("Simulation complete--sequence finished.");
  45.         } catch (InterruptedException e) {
  46.             log.info("Caught the interrupt exception while sleeping.");
  47.         }
  48.         log.info("Exiting StatusServlet.destroy()");
  49.     }
  50.  
  51.     public String getServletInfo() {
  52.         return "....";
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement