This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance tuning in date validation  RSS feed

 
Karthik Veeramani
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read the udp port and process the message, at a fast rate. as per protocol, i should check if there is a timestamp in the beginning of the message. This timestamp should only be in a specific format (like Jan 10 10:00:00). If i dont find this timestamp, i have to insert one myself.
My problem is, as this should be done for every message, i dont know how efficiently i can do this. Is there an easier way to validate the timestamp? right now, ive only thought of 1 thing - take the 1st 3 tokens, check the 1st token against a list of strings like Jan, Feb... , check if the other numbers r within the correct range, etc.
Please give me any kind of performance tips related to this (not only related to the parsing logic, but also on which classes to use to get better performance etc.)
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at SimpleDateFormat?

you can also use the parse method to validate date structure( i.e. sdf.parse("Jan 10 10:00:00") will throw an exception if the format is wrong, otherwise it creates a java.util.Date )
Just another idea.
Jamie
 
Karthik Veeramani
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much. I'll knew about SimpleDateFormat, but wasnt aware of parse method. I'll look into it. thnx again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!