tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup Catalina.java
Date Tue, 18 Dec 2001 15:50:28 GMT
remm        01/12/18 07:50:28

  Modified:    catalina/src/share/org/apache/catalina/startup Catalina.java
  Log:
  - Bug 5484 mentioned a shutdown hook, and that reminded me that Catalina
    doesn't set one which could be used to try to do a clean shutdown of the
    server when the process is killed (under Windows, it happens often when ^C
    is used to close the server). This patch adds a shutdown hook which will
    stop the server object.
  
  Revision  Changes    Path
  1.42      +37 -5     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java
  
  Index: Catalina.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Catalina.java	2001/12/02 19:22:23	1.41
  +++ Catalina.java	2001/12/18 15:50:28	1.42
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
1.41 2001/12/02 19:22:23 patrickl Exp $
  - * $Revision: 1.41 $
  - * $Date: 2001/12/02 19:22:23 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
1.42 2001/12/18 15:50:28 remm Exp $
  + * $Revision: 1.42 $
  + * $Date: 2001/12/18 15:50:28 $
    *
    * ====================================================================
    *
  @@ -97,7 +97,7 @@
    * </u>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.41 $ $Date: 2001/12/02 19:22:23 $
  + * @version $Revision: 1.42 $ $Date: 2001/12/18 15:50:28 $
    */
   
   public class Catalina {
  @@ -490,11 +490,15 @@
                   definition + "java.,org.apache.catalina.,org.apache.jasper.");
           }
   
  +        Thread shutdownHook = new CatalinaShutdownHook();
  +
           // Start the new server
           if (server instanceof Lifecycle) {
               try {
                   server.initialize();
                   ((Lifecycle) server).start();
  +                // Register shutdown hook
  +                Runtime.getRuntime().addShutdownHook(shutdownHook);
                   // Wait for the server to be told to shut down
                   server.await();
               } catch (LifecycleException e) {
  @@ -511,6 +515,7 @@
           if (server instanceof Lifecycle) {
               try {
                   ((Lifecycle) server).stop();
  +                Runtime.getRuntime().removeShutdownHook(shutdownHook);
               } catch (LifecycleException e) {
                   System.out.println("Catalina.stop: " + e);
                   e.printStackTrace(System.out);
  @@ -574,6 +579,34 @@
       }
   
   
  +    // --------------------------------------- CatalinaShutdownHook Inner Class
  +
  +
  +    /**
  +     * Shutdown hook which will perform a clean shutdown of Catalina if needed.
  +     */
  +    protected class CatalinaShutdownHook extends Thread {
  +
  +        public void run() {
  +
  +            if (server != null) {
  +                try {
  +                    ((Lifecycle) server).stop();
  +                } catch (LifecycleException e) {
  +                    System.out.println("Catalina.stop: " + e);
  +                    e.printStackTrace(System.out);
  +                    if (e.getThrowable() != null) {
  +                        System.out.println("----- Root Cause -----");
  +                        e.getThrowable().printStackTrace(System.out);
  +                    }
  +                }
  +            }
  +            
  +        }
  +
  +    }
  +
  +
   }
   
   
  @@ -609,4 +642,3 @@
   
   
   }
  -
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message