How to implement something like Try to get a value, if null then sleep a little without using Thread.sleep?
<p>At one point in my application, I need to ask a cache (a HashMap, i.e.) for a value. If the value does not exist, I need to wait a little and try again. At the moment, this is implemented like this:</p>

<pre><code>String result = cache.get(key);

for (int i = 0; result == null; i++) {
    try {
        Thread.sleep(5);
    } catch (InterruptedException e) {

    }

    result = cache.get(key);
}
</code></pre>

<p>While it works, I have a feeling that using <code>Thread.sleep</code> is kinda false. Does the JDK provide anything for this sort of task? I thought about using an <code>ScheduledExecutorService</code>, but the thing is that it has to run in the main thread.</p>
