Run Grizzly threaded
diff --git a/src/main/java/de/ids_mannheim/korap/KorapNode.java b/src/main/java/de/ids_mannheim/korap/KorapNode.java
index 18298ec..47f7009 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapNode.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapNode.java
@@ -115,9 +115,31 @@
// WADL available at BASE_URI + application.wadl
final HttpServer server = startServer();
- System.out.println("KorapNode started\nHit enter to stop it...");
- System.in.read();
- server.stop();
+
+ // Establish shutdown hook
+ Runtime.getRuntime().addShutdownHook(
+ new Thread(
+ new Runnable() {
+ @Override
+ public void run() {
+ log.info("Stup Server");
+ // staaahp!
+ server.stop();
+ }
+ },
+ "shutdownHook"
+ )
+ );
+
+ // Start server
+ try {
+ server.start();
+ log.info("You may kill me gently with Ctrl+C");
+ Thread.currentThread().join();
+ }
+ catch (Exception e) {
+ log.error("Unable to start server: {}", e.getLocalizedMessage());
+ };
};