I have a requirment to run a while loop the 5 min.
I looked for the timer api but I could not found to do this.
Can any one provide a code snipet for this.
Thanks
I have a requirment to run a while loop the 5 min. I looked
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.
The easiest way will be to just check how much time has elapsed on each iteration. Example:
This will run the loop, until more than 5 minutes have elapsed.
Notes:
System.nanoTime()is more suitable thanSystem.currentTimeMillis()because the latter will change if the computer’s system clock is adjusted, thus throwing off the calculation. Thanks to Shloim for pointing this out.