Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I schedule my java program(core java file) to run every day at a particular time? I want to schedule it in a Linux server and what is the same for Windows?

share|improve this question
4  
Voting to close as OT and moving to Super User - running a Java program is a matter of executing java -jar ..., the rest is OS-related configuration. –  Tomasz Nurkiewicz Feb 8 '12 at 9:59
add comment

migrated from stackoverflow.com Feb 8 '12 at 13:51

This question came from our site for professional and enthusiast programmers.

8 Answers

up vote 4 down vote accepted

For Linux, have a look at cron jobs.

First, install your cronjob by running the following command:

# crontab -e

To run a job everyday 5 minutes after midnight, append the following:

5 0 * * * /path/to/command

Save and close the file.

For Windows, have a look at scheduled tasks.

share|improve this answer
add comment

For linux you can use cron and to do the same thing on windows use quartz-scheduler.

Take a look here for crontab-examples.

share|improve this answer
add comment

you can use Quartz API to Schedule your daily/On-Time Jobs. Following is the link for Quartz API: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/

share|improve this answer
add comment

You can use linux Cron , yoy can also read good toturial in here: http://www.ibm.com/developerworks/linux/library/l-job-scheduling/index.html

also for scheduling in java program you can use java Api such as Timer class in java util but better approach using scheduling frameworks such as Quartz.

share|improve this answer
add comment

You can schedule your java program(task) using either Operating system services or using java.

1) Using Operating System Scheduler

for Linux, you can use Cron Jobs to schedule your program

for Windows, check the windows scheduler

2) using java.

you can use java.util.Timer class to schedule a TimerTask object.

make a separte thread for timertask and schedule it with

 Timer.schedule(TimerTask timertask, Datetime)
share|improve this answer
add comment

please use the following steps: 1. download and configure your application to use any of the Java services products , I use frequently this one : http://wrapper.tanukisoftware.com/doc/english/download.jsp

  1. schedule your software using any of the scheduling APIs available: cron4j (very small & reliable but does not cover all possible use cases) quartz scheduler , the rolls royce for scheduling but now heavyweight learn the Java 1.5 java.util.concurrent.ScheduledExecutorService and register a job (Runnable or Future) into this service depending from the API (all may use Runnable ,some support Future and add their own Job classes)

  2. learn the cron syntax to use any of the listed APIs and schedule your job

Quartz may add a lot of features with vetoable jobs , clustering and other advanced topics

HTH jerome

share|improve this answer
add comment

Since everyone already mentioned the obvious CLI options.

share|improve this answer
add comment

In Unix: You need to write a script with an .sh extension: something as simple as

echo "start"
java usr/bin/MyClass

would work

then add a entry to start it up under the crontab of the user you want to start the script with

In Windows: You need to create a bat file(same as scripts with .bat extension) Schedule in Windows Scheduler

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.