Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
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.
 
Sheriff
Posts: 22024
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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?
 
(instanceof Sidekick)
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.
 
All of the following truths are shameless lies. But what about this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic