J
Jeff
For a one time Timer, after the TimerTask's run method is executed, is the
TimerTask available to be garbage collected? I'm having a hard time proving
it, but I think the TimerTask persists after run() is executed. I could fix
it by explicitly calling .cancel() from the TimerTask, but I suspect the
language designers had a better solution in mind.
In this example, is FireJeffAlarm eligable for garbage collection after it's
run() is done?
Thanks
class JeffTimer extends java.util.Timer {
JeffTimer() {
schedule( new FireJeffAlarm() , 2000 );
System.out.println( " scheduled alarm" );
}
class FireJeffAlarm extends TimerTask {
public void run() {
System.out.println( "firing Jeff Alarm " );
} // run
} // FireJeffAlarm
public static void main( String args[] ) {
JeffTimer timer = new JeffTimer();
}
}
TimerTask available to be garbage collected? I'm having a hard time proving
it, but I think the TimerTask persists after run() is executed. I could fix
it by explicitly calling .cancel() from the TimerTask, but I suspect the
language designers had a better solution in mind.
In this example, is FireJeffAlarm eligable for garbage collection after it's
run() is done?
Thanks
class JeffTimer extends java.util.Timer {
JeffTimer() {
schedule( new FireJeffAlarm() , 2000 );
System.out.println( " scheduled alarm" );
}
class FireJeffAlarm extends TimerTask {
public void run() {
System.out.println( "firing Jeff Alarm " );
} // run
} // FireJeffAlarm
public static void main( String args[] ) {
JeffTimer timer = new JeffTimer();
}
}