Search code examples
javajettyembedding

Is an embedded Jetty Server guaranteed to be "ready for business" when the call to Server.start() returns?


I am having trouble finding any information about whether an embedded Jetty Server is guaranteed to be fully initialized and ready to receive requests when the call to Server.start() returns.

Nor have I been able to find anything conclusive by debugging.

If the server might still be initializing itself when the call returns, is there any way to register a callback so that I can be notified when it is indeed ready for action?


Solution

  • Yes, when returning from Server.start() the server is ready.

    You can register a LifeCycle.Listener using Server.addLifeCycleListener(listener) to get notified of startup or shutdown events. If you look at the source of Server.start() you'll see, that it calls Listener.lifeCycleStarted() at the end.