Hi, I need to schedule a java application to run at a particular point in the day. I am aware of the Timer & Timer task classes,but am not sure/confident abt using it. If anyone of a good way of doing it plz do let me know i desperately need to know thanks in advance Sharun
You could give your java class a "main()" method, and then invoke it using the OS scheduler as an application. Alternatively, have an application that creates a new thread. The thread will check the time and then sleep for a while. If the time is appropriate it can do it's stuff. If you do this, you should set a "date last run" variable so that it doesn't run twice on the same day. Does this help ?
I recently started using a 3rd party library called Quartz and it is GREAT! http://www.quartzscheduler.org/quartz/ It's free, open-source, and is VERY well documented. I highly recommend it. In your case, you would just have to create a new class that extends Job and in the execute() method does your work or just calls yours class. Then you setup a Trigger with the settings for the time you want it to run. Then you add those to the Scheduler tell the Scheduler to start. It's really simple - give it a try. Read the tutorial they have online. brian
This is a feature of the operating system. Otherwise you program must run continuously, and only fire certain methods at the appointed time. Both windows and Linux have facilities to run programs at certain times. That is what you need.
Originally posted by Geoffrey Falk: Write a program to run as follows: 1) Calculate the difference between the start time and the current time 2) Sleep for that amount of time 3) Start doing its thing. Geoffrey
Not the preferred way to do this. Preferred way is to use the OS facilities. That way you have better error handling and consistency. Your program must keep checking the clock else your time count will be off when your program gets preempted. No need to keep program in RAM when its not needed. TSRs sucketh.
I agree, leaving a Java programme running constantly in order that it can do something at a particular time is not really good practice. If you're using windows for example, write your Java class complete with a main() method. Then you can simply create a .bat file containing the java command to run the application.
Now in windows, using 'scheduled tasks' you can set the batch file to run once a day or whatever and your Java program will run. I think
Depends which environment this needs to run. On backend unix systems, it usually works with a cronjob. just do a google search for this. This can run at any time you want. Then create an executable jar, with the right manifest and main class and there you go....
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.