10 |
|
import junit.framework.*; |
11 |
|
import java.util.*; |
12 |
|
import java.util.concurrent.*; |
13 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
|
import java.util.concurrent.locks.*; |
15 |
|
import java.io.*; |
16 |
|
|
330 |
|
sync.acquire(1); |
331 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
332 |
|
public void realRun() throws InterruptedException { |
333 |
< |
sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000); |
333 |
> |
sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS)); |
334 |
|
}}); |
335 |
|
|
336 |
|
t.start(); |
337 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
338 |
|
t.interrupt(); |
339 |
|
t.join(); |
340 |
|
} |
364 |
|
sync.acquire(1); |
365 |
|
Thread t = new Thread(new CheckedRunnable() { |
366 |
|
public void realRun() throws InterruptedException { |
367 |
< |
threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000)); |
367 |
> |
long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS); |
368 |
> |
assertFalse(sync.tryAcquireNanos(1, nanos)); |
369 |
|
}}); |
370 |
|
|
371 |
|
t.start(); |
421 |
|
sync.acquireInterruptibly(1); |
422 |
|
Thread t = new Thread(new InterruptedSyncRunnable(sync)); |
423 |
|
t.start(); |
424 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
425 |
|
t.interrupt(); |
426 |
|
assertTrue(sync.isHeldExclusively()); |
427 |
|
t.join(); |
481 |
|
final Mutex sync = new Mutex(); |
482 |
|
final AbstractQueuedLongSynchronizer.ConditionObject c = sync.newCondition(); |
483 |
|
sync.acquire(1); |
484 |
< |
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
484 |
> |
assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS)); |
485 |
|
sync.release(1); |
486 |
|
} |
487 |
|
|
791 |
|
public void realRun() throws InterruptedException { |
792 |
|
sync.acquire(1); |
793 |
|
c.await(); |
790 |
– |
sync.release(1); |
794 |
|
}}); |
795 |
|
|
796 |
|
t.start(); |
809 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
810 |
|
public void realRun() throws InterruptedException { |
811 |
|
sync.acquire(1); |
812 |
< |
c.awaitNanos(1000 * 1000 * 1000); // 1 sec |
810 |
< |
sync.release(1); |
812 |
> |
c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); |
813 |
|
}}); |
814 |
|
|
815 |
|
t.start(); |
830 |
|
sync.acquire(1); |
831 |
|
java.util.Date d = new java.util.Date(); |
832 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
831 |
– |
sync.release(1); |
833 |
|
}}); |
834 |
|
|
835 |
|
t.start(); |
956 |
|
|
957 |
|
Thread t = new Thread(new CheckedRunnable() { |
958 |
|
public void realRun() throws InterruptedException { |
959 |
< |
threadAssertFalse(l.isSignalled()); |
960 |
< |
threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000)); |
961 |
< |
threadAssertTrue(l.isSignalled()); |
959 |
> |
assertFalse(l.isSignalled()); |
960 |
> |
long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS); |
961 |
> |
assertTrue(l.tryAcquireSharedNanos(0, nanos)); |
962 |
> |
assertTrue(l.isSignalled()); |
963 |
|
}}); |
964 |
|
|
965 |
|
t.start(); |
994 |
|
final BooleanLatch l = new BooleanLatch(); |
995 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
996 |
|
public void realRun() throws InterruptedException { |
997 |
< |
threadAssertFalse(l.isSignalled()); |
998 |
< |
l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000); |
997 |
> |
assertFalse(l.isSignalled()); |
998 |
> |
long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); |
999 |
> |
l.tryAcquireSharedNanos(0, nanos); |
1000 |
|
}}); |
1001 |
|
|
1002 |
|
t.start(); |
1013 |
|
final BooleanLatch l = new BooleanLatch(); |
1014 |
|
Thread t = new Thread(new CheckedRunnable() { |
1015 |
|
public void realRun() throws InterruptedException { |
1016 |
< |
threadAssertFalse(l.isSignalled()); |
1017 |
< |
threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000)); |
1016 |
> |
assertFalse(l.isSignalled()); |
1017 |
> |
long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); |
1018 |
> |
assertFalse(l.tryAcquireSharedNanos(0, nanos)); |
1019 |
|
}}); |
1020 |
|
|
1021 |
|
t.start(); |