From 18d2c3297c94b6bdb179270c97327187eb1a7945 Mon Sep 17 00:00:00 2001 From: Larry Sachs Date: Mon, 10 Oct 2016 14:21:13 -0700 Subject: [PATCH] Keep SimpleServer Alive Change-Id: Ia91714e660546de5c1b0002956475f03b1e0f1d1 Signed-off-by: Larry Sachs Reviewed-on: https://gerrit.iotivity.org/gerrit/13053 Tested-by: jenkins-iotivity Reviewed-by: Rick Bell --- .../main/java/org/iotivity/base/examples/SimpleServer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java b/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java index a5c2883..446fb8a 100644 --- a/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java +++ b/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java @@ -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) { -- 2.7.4