tags:

views:

90

answers:

4

Have any one scheduled a java program to run at particular time of day? Does platform make any difference? I am using Windows.

A: 

If you're on windows, and you have an executable, how about using the Windows Scheduler?

EDIT
Since you're not actually using windows: I don't know of any way to schedule something that still runs in debug (except, of course, compiling to an executable anyway).

I'm not familiar with Unix, but it looks like you'll need some kind of scheduler on Unix (if one isn't already installed) and do the same thing: essencially schedule the OS to call the executable- passing in whatever arguments are necessary.

AllenG
Since I am testing it currently, I can't go for that option as my eventual production system is unix. So I want to make sure that the program runs as scheduled.
yogsma
then why do you even mention Windows in the question?
DaveE
A: 

You can use windows task schedule to schedule your program.

Giorgi
+2  A: 

For unix-like platforms there is cron. This Stackoverflow question covers alternatives on Windows.

rlovtang
How can I create executable from java file? "main" method is in different java file which calls this file.
yogsma
In your comment below, you say that your final target is Unix. cron is the standard job scheduler on Unix-like systems. Compiling your Java program is a whole separate question. You'll likely end up with a .jar that will need to be run. If an appropriate JVM is available on your Windows system, your program execution will be similar on both platforms.
DaveE
@DaveE - You are right. I will have jar file finally. I mentioned platform just for additional information. I know that confused with windows scheduling or unix scheduling.
yogsma
+2  A: 

You could of course let the Java program run constantly, and schedule the work to do there. I don't know if that's an option for you, but at least you get platform independence. For scheduling in Java there's different options like Quartz, java.util.Timer/java.util.TimerTask, etc. I guess there are so questions rating the different alternatives.

rlovtang
I am using Timer and TimerTask.
yogsma