0

Possible Duplicate:
How to schedule a periodic task in Java?

I need to write a method (in a thread) that will work automatically everyday at 00:05. (method will be run on server).

I've looked it up in Google and on this site but all results were about different languages (mostly C#). How do I achieve that in Java?

Community
  • 1
  • 1
ronn jack
  • 181
  • 1
  • 3
  • 12

4 Answers4

2

It could be useful to take a look to Quartz project.

Here you can find some examples.

davioooh
  • 23,742
  • 39
  • 159
  • 250
0

Use a scheduler executor service; it has an option to run a task periodically (fixed rate). This should help you get started.

You should explore a third party library like quartz if you expect your scheduler based requirements to get complicated or grow.

Scorpion
  • 3,938
  • 24
  • 37
0

If you are using Java EE, you can use the TimerService, here is a tutorial: http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html

Rafael Sisto
  • 404
  • 5
  • 19
0

There are a number of approaches you could take. Look at the Java API for a java solution without a lot of dependencies.

You could also use Spring to leverage additional capabilities, and a more streamlined approach as is listed is this bit of documentation.

Bill
  • 2,623
  • 1
  • 27
  • 41