简体   繁体   中英

Scheduling micro tasks in Java

I have a scanario whereby I'd like to replay events from a file into JMS respecting the timestamps of each event.

There are many hundreds of thousands of events. Some events are only one or two milliseconds apart some are seconds apart.

Any suggestions on the best way to do this would be very much appreciated.

here's what i'd try, and in this order:

  1. use quartz . i dont see why it wont be able to handle hundreads of thousands of events.
  2. if for some reason quartz doesnt fit, i'd take all the event timestamps (you said replay so im assumming you know them all inadvance), order them, and use a main thread + thread pool. the main thread sleep()s for the intervals between consecutive events and when its time to fire an event it sends the task of calling the handler out to the executor. if yo uwant better precision (and can live with busy waiting) i'd avoid sleep() and busywait

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