我有一个java应用程序,它嵌入了一个jetty服务器来提供http服务。
如果我通过 url 访问它:
http://localhost:8080/doStop
它将停止 jetty 服务器并自行终止。
我有两个选择:
1. calls `myserver.stop()`, which `myserver` is an instance of `org.mortbay.jetty.Server`, and had set `.setStopAtShutdown(true)`
2. just invoke `System.exit()`
我想知道仅调用 System.exit()
来停止整个应用程序是否安全?
最佳答案
当然,您可以使用 System.exit(0)
。
但是从服务器使用停止方法会更干净,并防止您出现意外错误(例如,仍然打开请求)。
关于java - 使用 `System.exit()` 停止具有嵌入式 Jetty 服务器的 Java 应用程序是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17938929/