File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Question

 
suresh kamsa
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 787
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are timer and timertask within the scope of 1.4 exam?
 
suresh kamsa
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me it worked as expected:
first:
"About to schedule task"
"Task scheduled"
.....later...........
"Time's up"
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barkat Mardhani:
Are timer and timertask within the scope of 1.4 exam?


Nope, they are not.
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Valentine....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic