Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
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
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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. It is configured on the Server instance with the setGracefulShutdown(long) method. Here's an example of setting this via the jetty.xml file, where we specify a "grace" period of 1000 milliseconds:

The "grace" period is the time the container will wait for requests currently inside the container to finish processing before shutting down.

As soon as the shutdown command is given, the container will close the connectors so that they do not accept any more inbound connections. This will inform most load balancers that the server is no longer part of the cluster. The contexts are closed so that they do not accept any more requests, but the requests currently inside the container will drain out and the Server instance will shutdown after the grace period expires.

You must also call the setStopAtShutdown(boolean) method with a value of true for the grace period to take effect.

APIs For Shutdown Implementation

Even though Jetty will automatically handle a controlled shutdown if you use the setGracefulShutdown(long) method on the Server instance, sometimes you may want to implement your own shutdown handling, for example, shutting down just a single context or a connector. Here's how.

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.

  • No labels
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