java 嵌入式 Jetty 为什么要使用 join

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15924874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:18:14  来源:igfitidea点击:

Embedded Jetty why to use join

javamultithreadingjetty

提问by Loner shushman

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

从嵌入式 Jetty 教程中获取的示例建议如下:

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.

为什么我需要添加该行server.join()?没有它它工作正常。

采纳答案by AlexR

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.

join()一直阻塞,直到服务器准备好。它的行为类似于Jetty 线程池的Thread.join()调用join()。没有这个一切都可以工作,因为码头启动得非常快。但是,如果您的应用程序足够重,启动可能需要一些时间。调用join()保证在它之后服务器确实准备好了。