In addition to Tudor'sTudor's response, you also shouldn't write infinite loops - that's just silly. For servers that are intended to run for an unknown amount of time (possibly endlessly), I do
while (keepServerRunning) { // where 'keepServerRunning' is a simple boolean variable
...
...and then use a shutdown hook to set the value to false
which allows the server (and the JVM) to exit normally, without having to kill the task via kill -9
or a force close.
While it's theoretically possible that a service will run forever, it's just not good practice to pretend like that happens in reality. Clean up after yourself, and provide your apps a simple, clean way to exit normally whenever possible.