I need a method to be called in an App Server (Glassfish) every 5 seconds, no matter what. Are timers reliable enough for this? What are my options.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unless you are on a real time system no ‘timer’ is going to gve you that accuracy. Timers in general provide a ‘it will happen in at least the time you want… but maybe later’ sort of thing.
This is an underlying OS thing, not a Java thing.
Edit:
That being said… do you really mean ‘5 seconds exactly’ or will a few milliseconds later work? If a few milliseconds later works then a timer is fine. It is possible that sometimes that ‘few milliseconds’ could be several hundred however, depending in what is going on in the system (os as well as things like garbage collection in the VM).