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?
-
You can set up a schedule run in windows. – Sri Harsha Chilakapati Apr 23 '15 at 08:41
-
any URL for help to do this? – Madhusudan Apr 23 '15 at 08:42
-
1YEs, use [ScheduleExecutorService](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html) – janani Jan 08 '16 at 10:39
3 Answers
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. The Scheduler provides a "Create Basic Task" wizard for setting up these schedules.
You can also use an executable JAR instead of a batch file, provided that Windows has a file association between JAR files and Java.
You may need to specify the start directory if your task performs IO - see this thread.

- 42,007
- 12
- 107
- 146
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.

- 303,325
- 100
- 852
- 1,154

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

- 4,672
- 3
- 24
- 47