Keep SimpleServer Alive
authorLarry Sachs <larry.j.sachs@intel.com>
Mon, 10 Oct 2016 21:21:13 +0000 (14:21 -0700)
committerRick Bell <richard.s.bell@intel.com>
Mon, 7 Nov 2016 23:21:29 +0000 (23:21 +0000)
Change-Id: Ia91714e660546de5c1b0002956475f03b1e0f1d1
Signed-off-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13053
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java

index a5c2883..446fb8a 100644 (file)
@@ -107,10 +107,19 @@ public class SimpleServer {
     private final static String TAG = SimpleServer.class.getSimpleName();
 
     public static void main(String[] args) {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                stopSimpleServer();
+            }
+        });
+
         startSimpleServer();
+        while (true) {
+            sleep(1);
+        }
     }
 
-    public void sleep(int seconds) {
+    public static void sleep(int seconds) {
         try {
             Thread.sleep(seconds * 1000);
         } catch (InterruptedException e) {