检测嵌入式 Jetty 服务器何时完全初始化

发布于 2024-07-30 18:47:56 字数 150 浏览 3 评论 0原文

我已将 Jetty 嵌入到 java 应用程序中,并在 Jetty 服务器对象的实例上调用 start() 方法(在设置描述静态和动态 Web 内容的位置的处理程序列表之后)。 start() 调用是否会阻塞直到初始化完成? 如果没有,我如何确定服务器何时完全启动并准备好接收请求?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白况 2024-08-06 18:47:56

是的,当 Server.start() 返回时,服务器已完全初始化。 无需做任何其他事情。 文档并不清楚这种行为,但我只是通过查看代码来验证它。

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.

无人接听 2024-08-06 18:47:56

我们有一个嵌入式 Jetty 应用程序,其中包含数十个要初始化的插件 WARS 和 servlet...我在应用程序启动时从未遇到过浏览器请求超时的情况,因此服务器初始化过程非常快。 来检查 Jetty 服务器是否仍在启动或准备就绪

Server.isStarting()
Server.isStarted()
Server.isRunning()

但是,您可以通过检查HTH

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

把梦留给海 2024-08-06 18:47:56

下面是我如何在 ANT 中执行此操作的示例,一旦 jetty 应用程序准备就绪,就启动 Firefox

<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>

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>
哥,最终变帅啦 2024-08-06 18:47:56

start() 调用是否会阻塞直到初始化完成?

不会。它将在后台运行服务器

如果没有,我如何确定服务器何时完全启动并准备好接收请求?

您使用 org.eclipse.jetty.server.Server#join() 方法。

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

请参阅 [1] 了解更多信息。

[1] http://www.eclipse.org/jetty /documentation/9.3.x/embedding-jetty.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文