1 21 package com.db4o.foundation; 22 23 26 public class SimpleTimer implements Runnable { 27 28 private final Runnable _runnable; 29 private final int _interval; 30 31 public volatile boolean stopped = false; 32 33 public SimpleTimer(Runnable runnable, int interval, String name){ 34 _runnable = runnable; 35 _interval = interval; 36 Thread thread = new Thread (this); 37 thread.setDaemon(true); 38 thread.setName(name); 39 thread.start(); 40 } 42 43 public void stop(){ 44 stopped = true; 45 } 46 47 public void run() { 48 while(! stopped){ 49 Cool.sleepIgnoringInterruption(_interval); 50 if(! stopped){ 51 _runnable.run(); 52 } 53 } 54 } 55 } 56 | Popular Tags |