Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best practice to use timers to check current time and xml file records

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
I have an xml file which has some node showing time ranges.
I should check this time ranges and compare the current time with stored time ranges, if current time is within those time range, I need to perform some actions.

Are there any pattern or best practice for it?

Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are the time ranges stored? As a begin date/time and end/date time?

If so, convert them to a Date object using java.text.DateFormat and/or java.textSimpleDateFormat, create a new Date object without parameters (new Date() will give a Date object for the current moment) and use their compareTo methods.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply.
Problem that I can not resolve is, should I use a Timer to read the file in intevral and check the time range or there are other low overhead method for performing this?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timer should be fine. Set one to repeat every hour or minutes or whatever you need.

Does the file change? If not, it should be easy to read it once and schedule Timer events for time ranges that are in the future. Tools like Quartz and Cron handle complex schedules.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic