java 重新启动码头实例的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/103508/
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-29 11:02:57  来源:igfitidea点击:

Best way of restarting a jetty instance

javajetty

提问by

I'm using start.jar and stop.jar to stop and start my jetty instance. I restart by calling stop.jar, then start.jar. The problem is, if I don't sleep long enough between stop.jar and start.jar I start getting these random ClassNotFoundExceptions and the application doesn't work correctly.

我正在使用 start.jar 和 stop.jar 来停止和启动我的码头实例。我通过调用 stop.jar 重新启动,然后调用 start.jar。问题是,如果我在 stop.jar 和 start.jar 之间睡眠时间不够长,我会开始收到这些随机的 ClassNotFoundExceptions 并且应用程序无法正常工作。

Sleeping for a longer period of time between stop and start is my current option.

在停止和开始之间睡更长的时间是我目前的选择。

I also heard from someone that I should have something that manages my threads so that I end those before jetty finishes. Is this correct? The question I have about this is that stop.jar returns immediately, so it doesn't seem to help me, unless there's something I'm missing. Another option might be to poll the log file, but that's pretty ugly.

我还从某人那里听说我应该有一些东西来管理我的线程,以便我在码头完成之前结束它们。这个对吗?我对此的问题是 stop.jar 立即返回,所以它似乎对我没有帮助,除非我遗漏了什么。另一种选择可能是轮询日志文件,但这非常难看。

What's the best way of restarting jetty?

重新启动码头的最佳方法是什么?

Gilbert: The Ant task is definitely not a bad way of doing it. However, it sleeps for a set amount of time, which is exactly what I'm trying to avoid.

Gilbert:Ant 任务绝对不是一个糟糕的方法。但是,它会休眠一段时间,这正是我想要避免的。

回答by Tim Howland

Can you write a shell script that does something like this after calling shutdown and before calling startup?

你能写一个shell脚本在调用shutdown之后和调用startup之前做这样的事情吗?

LISTEN_PORT = `netstat -vatn | grep LISTEN| grep 8080 | wc -l `
while [$LISTEN_PORT -ne 0] ; do
    sleep 1
    LISTEN_PORT = `netstat -vatn | grep LISTEN| grep 8080 | wc -l `
done

回答by Tim Howland

This thread looks old but posting anyway, may help someone. A cross-platform approach:

该线程看起来很旧,但无论如何发布,可能会对某人有所帮助。跨平台方法:

http://ptrthomas.wordpress.com/2009/01/24/how-to-start-and-stop-jetty-revisited/

http://ptrthomas.wordpress.com/2009/01/24/how-to-start-and-stop-jetty-revisited/

回答by Tim Howland

Did you try JFGI? Setting up Ant task that could do the work for you?

你试过JFGI吗?设置可以为您完成工作的 Ant 任务?

This blog post details how to setup targets that can start and stop jetty for you. You could easily cobble together another target called 'jetty-restart' which depends on 'jetty-stop' and then calls 'jetty-start'.

这篇博文详细介绍了如何设置可以为您启动和停止码头的目标。您可以轻松拼凑另一个名为“jetty-restart”的目标,该目标取决于“jetty-stop”,然后调用“jetty-start”。

http://ptrthomas.wordpress.com/2006/10/10/how-to-start-and-stop-jetty-from-ant/

http://ptrthomas.wordpress.com/2006/10/10/how-to-start-and-stop-jetty-from-ant/