java - Timer.schedule() leaves an open thread after execution -
i'm trying use timer.schedule()
schedule operation happen 1s after. problem i'm having after operation executed, there's open thread left hanging , i'm forced ctrl+c close it.
am doing wrong? how stop timer leaving open thread?
public class myclass { public static int waiting_window = 1000; private boolean waiting = true; public myclass() {} public void mymethod() { new timer().schedule( new timertask() { @override public void run() { setwaiting(false); } }, waiting_window ); } public void setwaiting(boolean waiting) { this.waiting = waiting; } }
keep reference timer
, call timer.cancel()
. , read javadocs, it's documented there!
Comments
Post a Comment