How to gracefully shutdown


Added by Greg Wilkins, last edited by Jan Bartel on Nov 20, 2006  (view change)

Labels

 
(None)
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery

Graceful shutdown

Graceful shutdown of a server, context or connector is when existing request/connections are allowed to gracefully complete while no new requests and/or connections are accepted.

Jetty 6 does not directly support graceful shutdown, but it can be achieved by various API calls.

Graceful context shutdown

The ContextHandler and all the classes derived from it (Context, WebAppContext) has a setShutdown(boolean) method, which if passed true will prevent the context from accepting new requests. Requests that are currently being handled by the context are not affected.

Requests that are rejected by a shutdown context are passed to the next configured context that matches the context path. Note that several contexts can be registered for the same context path, so a new context (or a notification of maintenance context) may be revealed by a shutdown context.

A setShutdown(false) can be called to allow the context to continue handing new requests.

Once a context is shutdown and the number of requests has reduced to zero (or near zero), then stop() should be called to actually stop the components of the context.

The ContextHandler.setShutdown(boolean) method is exposed on via an MBean and can be called from a management agent.

Graceful connector shutdown

The Connector.close() method can be called to close the server socket on which a connector is listening. This will prevent new connections from being accepted and inform most load balancers that the server is no longer part of a cluster. Existing client connections can continue to run until they timeout or stop() is called on the connector.

A closed connector should be stopped before being restarted. Connector.open() cannot be called on a started connector.

  1. Jul 07, 2006

    Andriy Zhdanov says:

    Hi Greg, we can't find any attributes or operations in MBean org.mortbay.jetty.h...

    Hi Greg, we can't find any attributes or operations in MBean org.mortbay.jetty.handler:type=contexthandler,id=0.

    Actually, all of the mortbay beans are empty (null descriptions, and no attributes and operations).

    We use jetty-6.0.0beta17, and started it with jetty-jmx.xml, as follows, but with platformBeanServer:

    java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3939 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar start.jar etc/jetty-jmx.xml etc/jetty.xml

    Following code works, but...

    String jmxServiceUrl =
    	        "service:jmx:rmi:///jndi/rmi://localhost:3939/jmxrmi";
            MBeanServerConnection mbs =
                JMXConnectorFactory.connect(
                    new JMXServiceURL(jmxServiceUrl), null).
                    getMBeanServerConnection();
    		ObjectName oname =
    			new ObjectName("org.mortbay.jetty.handler:type=contexthandler,id=0");
    		MBeanInfo oinfo = mbs.getMBeanInfo(oname);
    
            MBeanAttributeInfo[] attributes = oinfo.getAttributes();
            System.out.println("#attributes: " + attributes.length);

    ... shows that there're no attributes

    #attributes: 0

    Can you help?