// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

public class RealTimer {
    public static void main(String[] args) throws IOException {
        Timer timer = new Timer();
        timer.schedule(new DoSomethingTask(), 1000, 1000);
        System.in.read();
        timer.cancel();
    }
}

class DoSomethingTask extends TimerTask {
    private long t;
    public DoSomethingTask() {
        t = System.currentTimeMillis();
    }
    private static void dosomething() throws InterruptedException {
        // simulate that it takes some time
        Thread.sleep(100);
    }
    public void run() {
        try {
            dosomething();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long t2 = System.currentTimeMillis();
        System.out.printf("%5.3f seconds\n", (t2 - t)/1000.0);
        t = t2;
    }
}
