2

I did a reminder application in java.I want to run that application only at 12 P.M So that it then generates a mail to client .The thing to generate mail is done,but the main issue now is how to make application run exactly at 12 P.M daily...

tgkprog
  • 4,493
  • 4
  • 41
  • 70
  • 4
    This is not a java question, it is purely dependant on your system. What OS are you using? – will Nov 19 '14 at 14:22
  • *or* you can make the app run as a daemon/service, with `Timer` scheduled to run on 12PM with interval set to 24 hours... seems simpler and less OS dependent IMO. –  Nov 19 '14 at 14:27
  • windows 8 and should I make my system a server – rishab dharewal Nov 19 '14 at 14:30

4 Answers4

2

Use cron (Unix only)

Add this to your cron tab

0 0 * * * /path/to/your/file.sh >/dev/null 2>&1

file.sh

#!/bin/sh
java com.package.YourMainClass

edit

On Windows 8, take a look here : Using Task Scheduler in Windows 8

ToYonos
  • 16,469
  • 2
  • 54
  • 70
1

You can keep the application running and do the scheduling yourself. For example, using Quartz

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
0

If you're on UNIX, you can use cron.

Lawrence Aiello
  • 4,560
  • 5
  • 21
  • 35
0

It can be solved in two ways. 1. Have the OS run it once a day using cron or other scheduler.

  1. The other is to install your program as serice using http://sourceforge.net/projects/yajsw/ or other service wrapper helper.

Then have your program run in the back ground, with a timer every minute. When its time, do the tasks. This is great as your program can easily accept config for other triggers as well. Advantage of installing it as a service is that it will run automatically on system start and keep running in the back ground. Make sure you catch exceptions, log them but try to keep running so the program does not exit on recoverable and transient errors.

In both cases you will make a non UI program with an optional UI program that writes to java preferences API to tell the daemon any user specific preferences.

The service app can be run from command line as well if you dont want to install a few users do not want to install it as a service.

For timer can see How to set a timer in java

Community
  • 1
  • 1
tgkprog
  • 4,493
  • 4
  • 41
  • 70