Author: xor
Date: 2008-11-07 22:33:34 +0000 (Fri, 07 Nov 2008)
New Revision: 23394

Modified:
   trunk/plugins/WoT/IdentityInserter.java
Log:
Make the thread shutdown properly instead of being killed by the node.

Modified: trunk/plugins/WoT/IdentityInserter.java
===================================================================
--- trunk/plugins/WoT/IdentityInserter.java     2008-11-07 20:54:05 UTC (rev 
23393)
+++ trunk/plugins/WoT/IdentityInserter.java     2008-11-07 22:33:34 UTC (rev 
23394)
@@ -48,7 +48,8 @@
        /** The TempBucketFactory used to create buckets from Identities before 
insert */
        final TempBucketFactory tBF;
        /** Used to tell the InserterThread if it should stop */
-       boolean isRunning;
+       private boolean isRunning;
+       private Thread mThread;

        /**
         * Creates an IdentityInserter.
@@ -69,10 +70,13 @@
         * it exports to XML and inserts OwnIdentities that need it.
         */
        public void run() {
+               mThread = Thread.currentThread();
+               
                try{
                        Thread.sleep((long) (3*60*1000 * (0.5f + 
Math.random()))); // Let the node start up
                } catch (InterruptedException e){}
                while(isRunning) {
+                       Logger.debug(this, "IdentityInserter loop running...");
                        ObjectSet<OwnIdentity> identities = 
OwnIdentity.getAllOwnIdentities(db);
                        while(identities.hasNext()) {
                                OwnIdentity identity = identities.next();
@@ -90,6 +94,7 @@
                                }
                        }
                        db.commit();
+                       Logger.debug(this, "IdentityInserter loop finished...");
                        try{
                                Thread.sleep((long) (THREAD_PERIOD * (0.5f + 
Math.random())));
                        } catch (InterruptedException e){}
@@ -100,8 +105,13 @@
         * Stops the IdentityInserter thread.
         */
        public void stop() {
+               Logger.debug(this, "Stopping IdentityInserter thread...");
                isRunning = false;
-               Logger.debug(this, "Stopping IdentityInserter thread");
+               mThread.interrupt();
+               try {
+                       mThread.join();
+               } catch(InterruptedException e) { }
+               Logger.debug(this, "Stopped IdentityInserter thread.");
        }

        /**


Reply via email to