import java.util.Timer; import java.util.TimerTask; public class Reminder { Timer timer; public Reminder(int seconds) { timer = new Timer(); timer.schedule(new RemindTask(), seconds*1000); } class RemindTask extends TimerTask { public void run() { System.out.println("Time's up"); // l4 timer.cancel(); } } public static void main(String args[]) { System.out.println("About to schedule task "); // l1 new Reminder(58); l2 System.out.println("Task scheduled"); l3 } } Any one explain me the execution flow of above example. According to me l1,l2,l3,l4 should get executed. After priting l1 it should wait for some time to print l2 instead of its print l1,l3 waiting for some time then printing l4. AFter printing l1 control should go to Constructor and wait for some time(seconds). Why is not doing? Thanks.
Barkat Mardhani
Ranch Hand
Joined: Aug 05, 2002
Posts: 787
posted
0
Are timer and timertask within the scope of 1.4 exam?
suresh kamsa
Ranch Hand
Joined: Jul 30, 2001
Posts: 149
posted
0
Sorry for not keeping the code in UBB. I don't know whether Timer and TimerTask is in the scope of 1.4 or not. I was going through tutorial and not able to understand what is going on.
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
posted
0
For me it worked as expected: first: "About to schedule task" "Task scheduled" .....later........... "Time's up"
SCJP2. Please Indent your code using UBB Code
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Originally posted by Barkat Mardhani: Are timer and timertask within the scope of 1.4 exam?