How to schedule a java program to run daily in Win

2019-01-23 22:41发布

问题:

I have written a Java program which retrieves Google data till present date using Google Analytic API and export it as CSV file. I want this program to run daily so that data in the CSV file will be up to date. How can I achieve this?

回答1:

You can use the Windows Task Scheduler (see tutorial) to start any program; for Java, you will probably want to create a batch file to run your Java program, then use the Scheduler to run the batch file.

You can also use an executable JAR.

You may need to specify the start directory - see this thread.



回答2:

Schedule Via Java

Use a ScheduledExecutorService and the method scheduleAtFixedRate with a TimeUnit of Day. Your program will wait a day and then do what it has to do.

Of course your computer has to be on. If that is an issue, it might be better do something like this using Google App Engine.



回答3:

Have a look at Windows Task Scheduler. Task scheduling can be found under all programs -> accessories -> system tools -> scheduled tasks.