379 |
*/ |
*/ |
380 |
static void sleep(long ms, int ns) throws InterruptedException |
static void sleep(long ms, int ns) throws InterruptedException |
381 |
{ |
{ |
|
|
|
|
// Round up |
|
|
ms += (ns != 0) ? 1 : 0; |
|
|
|
|
382 |
// Note: JDK treats a zero length sleep is like Thread.yield(), |
// Note: JDK treats a zero length sleep is like Thread.yield(), |
383 |
// without checking the interrupted status of the thread. |
// without checking the interrupted status of the thread. |
384 |
// It's unclear if this is a bug in the implementation or the spec. |
// It's unclear if this is a bug in the implementation or the spec. |
385 |
// See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203 |
// See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203 |
386 |
if (ms == 0) |
if (ms == 0 && ns == 0) |
387 |
{ |
{ |
388 |
if (Thread.interrupted()) |
if (Thread.interrupted()) |
389 |
throw new InterruptedException(); |
throw new InterruptedException(); |
403 |
{ |
{ |
404 |
while (true) |
while (true) |
405 |
{ |
{ |
406 |
vt.wait(ms); |
vt.wait(ms, ns); |
407 |
now = System.currentTimeMillis(); |
now = System.currentTimeMillis(); |
408 |
if (now >= end) |
if (now >= end) |
409 |
break; |
break; |
410 |
ms = end - now; |
ms = end - now; |
411 |
|
ns = 0; |
412 |
} |
} |
413 |
} |
} |
414 |
} |
} |