Is it possible to use `System.exit ()` to stop the java application with the embedded Jetty server?

I have a java application that includes a berth server for providing http services.

If I find it through the url:

http://localhost:8080/doStop 

he will stop the berth server and complete it himself.

I have two options:

 1. calls `myserver.stop()`, which `myserver` is an instance of `org.mortbay.jetty.Server`, and had set `.setStopAtShutdown(true)` 2. just invoke `System.exit()` 

I wonder if you can just call System.exit() to stop the whole application?

+4
source share
2 answers

Of course you can use System.exit(0) .

But using the stop method from the server will be much cleaner and prevent unexpected errors (for example, still open request).

+2
source

System.exit() is safe if you do not have resources to release, semi-arid data that you need to save, or want the server to complete servicing any open requests before closing.

As a rule, System.exit() is considered harmful because you can forget that you (or you don’t know that your colleague) had something effective related to the shutdown event.

+1
source

Source: https://habr.com/ru/post/1494193/


All Articles