简体   繁体   中英

How to create Timer Service using Java, Netbeans, and Glassfish

I want to have a method run every day at 3am that will summarize a production database and insert into another database. I've seen examples of the Timer services with Java but I'm not sure that is what I am looking for. I want the program to execute on its own with me having to worry about it starting up at 3am do its work and go to sleep until 3am the next day so and so on. Any Links to pre-existing questions, blogs, or guides will be much appreciated(if there are any), thanks.

您可以尝试使用java.util.Timerjava.util.TimerTask

There are many ways you can schedule jobs to run at a specified intervals

  1. java.util.concurrent.ScheduledExecutorService
  2. Cron Jobs - You can create your own job to run
  3. Quartz scheduler - powerful API to schedule jobs
  4. Autosys Job scheduler

The Quartz Scheduler library provides triggers to execute at a given date time or regular intervals (every day, every year, etc). You declare the schedule using a very simple trigger expression, like Cron.

See these links for more information:

You can also use the Java EE Timer Service and annotation to specify when the timer runs.

@Schedule(dayOfWeek="Sun", hour="0")
public void autoTimer() { ... }

http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM