On May 11, 2012, at 5:24 PM, Rob McKenna wrote:
> 
>> 
>> For the following code:
>> 
>>  227         long rem = end - now;
>>  228         while (!hasExited&&  (rem>  0)) {
>>  229             wait(TimeUnit.NANOSECONDS.toMillis(rem));
>>  230             rem = end - System.nanoTime();
>>  231         }
>> 
>> Can the above go into a spin loop once the duration is less than 1 
>> millisecond for the rest of that duration? If so you may want to round it up 
>> to the nearest millisecond.
> Eesh. wait(0) will wait until notified so we could end up waiting past our 
> timeout expiry. Would:
> 
> wait(Math.max(TimeUnit.NANOSECONDS.toMillis(rem), 1));
> 
> alleviate all concerns here?
> 

Yes, or you could use:

   wait(long timeout, int nanos)

Paul.

Reply via email to