Question: I'm using a timer to run a Cron Job in a Tomcat Server, it runs on startup and waits whichever amount of minutes I assign. Right now, Im assigning it to run every 24 hours.

web-xml configuration: 

```
 <env-entry>
    <description>Minutes to Parse - 1440 minutes = 1 day</description>
    <env-entry-name>Minutes</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>1440</env-entry-value>
  </env-entry>

```

Cron Job configuration:

```
private void startScheduler() {
        try {
            timer.schedule(new TimerTask() {
                public void run() {
                    scheduleParse();
                    //timer.cancel();
                }
                private void scheduleParse() {
                    notificaciones();
                    System.out.println("Lo esta haciendo");
                }
            }, 0, this.minutes * 60 * 1000);
        }
        catch (Exception e) {
        }
    }

```

But I need my function to run at midnight every day and by the way we are doing it, it is running every 24 hours taking as a reference the time the deploy was made. For example, if we deploy our web application at 10 am today, it will be running every day at 10 am. 

I found a solution, but I want to know if there is a better one for this. The time interval will be every 60 minutes... if the actual hour is 12 am, the process will be made. If it is not, nothing will be done. 

Is there a better solution for this?

Answer: 
I think I'd be tempted to use the scheduling software of your server environment to trigger the job, rather than try to handle the scheduling yourself. If your scheduler thread dies for any reason, you'll never run the job again without retarting the app server.

On Unix, you can use cron tabe to trigger the job. An array of more sophisticated tools exist on both Unix and Windows, but even cron should give you the sort of control that you are looking for.
You could try [quartz-scheduler](http://quartz-scheduler.org/). There are nice examples, [here](http://quartz-scheduler.org/documentation/quartz-2.1.x/cookbook/DailyTrigger).