diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java index 34b550df67140765d9ea7ab0fd1580f1b592e1ac..077acdb7f02bbf7f1a8c13cd912cac599d994078 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Daemon.java @@ -39,6 +39,7 @@ import net.i2p.I2PAppContext; public class Daemon { public static final String VERSION = "2.0.3"; private static final Daemon _instance = new Daemon(); + private boolean _running; /** * Update the router and published address books using remote data from the @@ -126,6 +127,7 @@ public class Daemon { } public void run(String[] args) { + _running = true; String settingsLocation = "config.txt"; File homeFile; if (args.length > 0) { @@ -166,7 +168,7 @@ public class Daemon { // Static method, and redundent Thread.currentThread().sleep(5*60*1000); } catch (InterruptedException ie) {} - while (true) { + while (_running) { long delay = Long.parseLong((String) settings.get("update_delay")); if (delay < 1) { delay = 1; @@ -179,6 +181,8 @@ public class Daemon { } } catch (InterruptedException exp) { } + if (!_running) + break; settings = ConfigParser.parse(settingsFile, defaultSettings); } } @@ -192,4 +196,9 @@ public class Daemon { _instance.notifyAll(); } } + + public static void stop() { + _instance._running = false; + wakeup(); + } } diff --git a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java index b5afaaa2f5d6b680032e2c5c118ef0f73f4dbb9a..7c9e65994fc513571253e6d947b35aa7c264c434 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/DaemonThread.java @@ -51,4 +51,9 @@ public class DaemonThread extends Thread { //} Daemon.main(this.args); } -} \ No newline at end of file + + public void halt() { + Daemon.stop(); + interrupt(); + } +} diff --git a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java index fceecfe5397be64ca01ec05470c1548c1d9de9ce..beb225ca0d6d60fcea8b69585b24abcbf91240d8 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/Servlet.java @@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletResponse; * */ public class Servlet extends HttpServlet { - private Thread thread; + private DaemonThread thread; private String nonce; private static final String PROP_NONCE = "addressbook.nonce"; @@ -88,4 +88,9 @@ public class Servlet extends HttpServlet { //System.out.println("INFO: config root under " + args[0]); } + @Override + public void destroy() { + this.thread.halt(); + super.destroy(); + } }