Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

schedule method in timer class

 
Joel Bijapurkar
Greenhorn
Posts: 20
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the method :



schedule a task for execution only once or does it schedule the task for execution repeatedly on the specified date and time?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the javadoc say ?
What happened when you tried it ?
 
Joel Bijapurkar
Greenhorn
Posts: 20
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The javadoc says that when we use the schedule(Timer task, Date time) function the specified task is scheduled for execution but does not explicitly mention if the task will be executed once or repeated. I tried it and it works as long as the NetBeans IDE is running.

When I close the IDE I get the following notification:

Exiting the IDE will close the following processes:
Process- Timer(run)

What should I do so that the program continues execution even after closing the IDE?

Here is the code I have created:



Thank you.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should I do so that the program continues execution even after closing the IDE?

The Java process used to run your application is a sub-process of the IDE, so when you close the IDE all of its sub-processes are closed and your application stops. If you want your app to run independently of the IDE you should run the application from the command prompt rather than from the IDE.
 
Joel Bijapurkar
Greenhorn
Posts: 20
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve. I found the solution. It is just as you said run the application from the command prompt. But in this case since I wanted to schedule the file for execution at a future time and date, I used a batch file. with the following code:



I then scheduled it using the windows scheduler and the following command:


and its working perfectly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic