I have embedded Jetty in a java application and am calling the start() method on an instance of the Jetty server object (after setting a handler list which describes the location of the static and dynamic web content). Does the start() call block until initialization is complete? If not, how do I determine when the server is fully started and ready to receive requests?
4 Answers
Yes, the server is completely initialized when Server.start() returns. There's no need to do anything else. The documentation isn't clear about this behavior, but I just verified it by looking at the code.

- 1,962
- 1
- 12
- 9
We have an embedded Jetty application with dozens of plug-in WARS and servlets to initialize...I've never had a browser request time out while the app was starting, so the server init process IS pretty fast. However, you can check if the Jetty server is still starting up or ready by checking
Server.isStarting()
Server.isStarted()
Server.isRunning()
HTH

- 413
- 2
- 8
Here's an example of how I've down this within ANT, launching firefox once the jetty application was ready
<parallel>
<jetty tempDirectory="${work.dir}">
<connectors>
<selectChannelConnector port="${jetty.port}"/>
</connectors>
<webApp name="ex1" warfile="ex1.war" contextpath="/ex1"/>
</jetty>
<sequential>
<waitfor maxwait="10" maxwaitunit="second">
<http url="http://localhost:${jetty.port}/ex1"/>
</waitfor>
<exec executable="firefox" spawn="yes">
<arg line="http://localhost:${jetty.port}/ex1"/>
</exec>
</sequential>
</parallel>

- 76,015
- 10
- 139
- 185
Does the start() call block until initialization is complete?
No. It will run the server in the background
If not, how do I determine when the server is fully started and ready to receive requests?
You use org.eclipse.jetty.server.Server#join()
method.
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See
// http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()
server.join();
See [1] fore more info.
[1] http://www.eclipse.org/jetty/documentation/9.3.x/embedding-jetty.html

- 3,282
- 5
- 41
- 48
-
1No, `join()` doesn't return when the server is ready to handle HTTP requests, it returns when the server has been shut down and is no longer running. – Darien Sep 05 '19 at 01:10