Author: xor
Date: 2008-11-01 12:37:40 +0000 (Sat, 01 Nov 2008)
New Revision: 23273

Modified:
   trunk/plugins/WoT/IdentityInserter.java
Log:
Use pseudo random intervals for Thread.sleep().

Modified: trunk/plugins/WoT/IdentityInserter.java
===================================================================
--- trunk/plugins/WoT/IdentityInserter.java     2008-11-01 11:47:20 UTC (rev 
23272)
+++ trunk/plugins/WoT/IdentityInserter.java     2008-11-01 12:37:40 UTC (rev 
23273)
@@ -39,6 +39,8 @@
  */
 public class IdentityInserter implements Runnable {

+       private static final int THREAD_PERIOD = 30 * 60 * 1000;
+       
         /** A reference to the database */
        ObjectContainer db;
         /** A reference the HighLevelSimpleClient used to perform inserts */
@@ -63,12 +65,12 @@
        }

        /**
-        * Starts the IdentityInserter thread. Every 30 minutes,
+        * Starts the IdentityInserter thread. About every 30 minutes (+/- 50%),
         * it exports to XML and inserts OwnIdentities that need it.
         */
        public void run() {
                try{
-                       Thread.sleep(30 * 1000); // Let the node start up (30 
seconds)
+                       Thread.sleep((long) (3*60*1000 * (0.5f + 
Math.random()))); // Let the node start up
                } catch (InterruptedException e){}
                while(isRunning) {
                        ObjectSet<OwnIdentity> identities = 
OwnIdentity.getAllOwnIdentities(db);
@@ -88,7 +90,7 @@
                        }
                        db.commit();
                        try{
-                               Thread.sleep(30 * 60 * 1000); // 30 minutes
+                               Thread.sleep((long) (THREAD_PERIOD * (0.5f + 
Math.random())));
                        } catch (InterruptedException e){}
                }
        }


Reply via email to