// 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.util.Timer;
import java.util.TimerTask;

public class TimerFun {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TestTask(), 1000, 2000);
        Thread.sleep(1000);
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        int nt = tg.activeCount();
        Thread[] t = new Thread[nt];
        tg.enumerate(t);
        for(int i = 0; i < nt; i++) {
            if(t[i] != Thread.currentThread()) {
                t[i].interrupt();
            }
        }
        Thread.sleep(1000);
        timer.cancel();
    }
}

class TestTask extends TimerTask {
    public void run() {
        System.out.println("Hejsa!!");
    }
}
