Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create a time out for a polling loop

800306Mar 9 2009 — edited Mar 10 2009
Hi,

I have a method call that starts an infinite loop that checks the status of some flag, and returns when the flag is set to true. However, I'd like the method call to return after a certain period of time, say five seconds; essentially a time out. I haven't been able to figure out how to implement this though.

I tried looking at something like java.util.Timer but that doesn't really seem to work; it seems as if the purpose of Timer is to schedule tasks. Whenever I search for ideas it just comes up with stuff about network connections timing out or whatever.

Can someone please give me an idea of how to go about implementing this?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2009
Added on Mar 9 2009
7 comments
1,165 views