Java - 'continue' loop iteration after certain timeout period

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-12-24T12:29:57Z Indexed on 2010/12/24 12:54 UTC
Read the original article Hit count: 205

Filed under:
|
|

Is there a way to exit ('continue;') a loop iteration after a certain timeout period?

I have a loop that will run gathering data from the web and then use this data to make a calculation.

The data become obsolete after about 1 to 2 seconds so if the loop iteration takes longer than 1 second then i want it to 'continue' to the next iteration.

Sometimes gathering the data can take time but sometimes the calculation can take longer than 1 second so a HTTP timeout won't work for what i need. Also, while doing the calculation the thread i am using is blocked so i cannot check System.currentTimeMillis();

Is there a way to use another Thread to check the time and force the original for loop to continue.

© Stack Overflow or respective owner

Related posts about java

Related posts about android