嵌入式码头为什么要使用联接 [英] Embedded Jetty why to use join

查看:157
本文介绍了嵌入式码头为什么要使用联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Embedded Jetty教程中的示例提出以下建议:

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();}

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

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

推荐答案

join()在服务器准备就绪之前一直处于阻塞状态.它的行为类似于Thread.join(),并且实际上调用了Jetty的线程池的join().没有码头,一切都会起作用,因为码头起步非常快.但是,如果您的应用程序很繁琐,则开始可能会花费一些时间.调用join()可以保证服务器确实准备就绪.

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.

这篇关于嵌入式码头为什么要使用联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆