Embedded Jetty why to use join

半世苍凉 提交于 2019-12-09 05:03:57

问题


An example taken from an Embedded Jetty tutorial suggests the following:

public static void main(String[] args) throws Exception
{
   Server server = new Server(8080);
   server.setHandler(new HelloHandler());

   server.start();
   server.join();}

Why do I need to add the line server.join()? It works fine without it.


回答1:


join() is blocking until server is ready. It behaves like Thread.join() and indeed calls join() of Jetty's thread pool. Everything works without this because jetty starts very quickly. However if your application is heavy enough the start might take some time. Call of join() guarantees that after it the server is indeed ready.



来源:https://stackoverflow.com/questions/15924874/embedded-jetty-why-to-use-join

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!