Java - planning a daily task

I am looking for an effective way to run a method on 3PM every day, regardless of when the application was launched or how long it took.

This should be done completely from within the application without OS intervention (e.g. Windows Task Scheduler)

I experimented with java.util.Timer in different configurations, but I did not succeed.

Any help would be appreciated.

Thanks.

+7
java timer scheduling task
source share
6 answers

You should take a look at Quartz , which is a Java-based task scheduling system.

+16
source share

You probably want to use something like a quartz engine , it can do things like completing tasks that you missed (for example, during the ahem crash) and it takes work out of trying to control flows.

For example, if you use streams and put them to sleep and wake it up for 86400 seconds (in one day), you wake up and will be late for an hour (day = 82800 seconds) or early (day = 90,000 seconds) when changing DST day, so be careful with any decision you choose

+2
source share

The built-in JDK method is to do what others have suggested and first compute:

  • currentTime - wishTime

Then you can use something like a schedule artist to send tasks and run them with a certain delay. This is much simpler than the parameters that you have with frameworks such as Quartz , but do not require an external dependency.

In addition, you should always indicate which JDK you are using, so people can provide solutions for your version of the JDK.

+2
source share

You can run a thread that calculates the difference until the next 3pm and sleeps for that time. When he wakes up, he executes the method and counts and sleeps. Is that what you meant?

+1
source share

As indicated by other Quartz, the choice is, with it you can do operations related to cron, tasks or triggers, here is a link to this topic: http://www.ibm.com/developerworks/java/library/j-quartz/index. html

+1
source share

Jcrontab

Jcrontab is a scheduler written in Java. The goal of the project is to provide fully functional graphics for Java projects.

+1
source share

All Articles