wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question" Watch "Thread Question" New topic
Author

Thread Question

suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
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
Are timer and timertask within the scope of 1.4 exam?
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
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
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
Originally posted by Barkat Mardhani:
Are timer and timertask within the scope of 1.4 exam?


Nope, they are not.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Thanks Valentine....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Question