/** * This method is the main function of the thread of the collective. It does housekeeping and * regularly talks to peers to exchange information. It can be stopped by calling <code>close() * </code>. * * @see #close() */ public final void run() { while (shouldLive) { // try{ System.gc(); removeOldStuff(); if (!refresh()) { Address[] a = observer.getPeerAddresses(); if (a != null) synchronized (cache) { for (int i = 0; i < a.length; ++i) cache.put(a[i].name, new ContributionBox(a[i], null)); } } for (int i = 0; i < REFRESHRATE; i += 1000) { try { Thread.sleep(1000); } catch (InterruptedException e) { shouldLive = false; } if (shouldLive == false) break; Thread.yield(); } /*} catch( RuntimeException e ) { Logger.error( "Collective#run()", "Runtime exception caught, something is going wrong",e); }*/ } cache = null; observer = null; }