I have the following piece of code to start a basic Embedded Grizzly server running with Jersey.
private static void startServer() {
ServerResourceConfiguration configuration = new ServerResourceConfiguration();
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
URI.create(BASE_URI),
configuration,
false,
null,
false);
server.start();
if (System.in.read() > -2) {
server.shutdownNow();
}
}
This does not look like production level way to stop a server. What is the best practice to gracefully shut it down ? I guess a terminal command of some sort. Killing the process would work but it is not very graceful.
I am using Gradle on this project and runs the server with the gradle run
command.
Could a Gradle task do the job?
Also I have seen this about gracefully terminating a grizzly transport: http://grizzly-nio.net/2013/08/gracefully-terminating-a-grizzly-transport/ But I am not sure if I would need to use it. I don't understand how to use it.
EDIT: I came across this post: https://stackoverflow.com/a/15391081/3982755 Is that an acceptable way to terminate an Http server in a production environment?