equal
deleted
inserted
replaced
38 import java.util.Collection; |
38 import java.util.Collection; |
39 import java.util.concurrent.CountDownLatch; |
39 import java.util.concurrent.CountDownLatch; |
40 import java.util.concurrent.Semaphore; |
40 import java.util.concurrent.Semaphore; |
41 import java.util.concurrent.ThreadLocalRandom; |
41 import java.util.concurrent.ThreadLocalRandom; |
42 |
42 |
43 import junit.framework.AssertionFailedError; |
|
44 import junit.framework.Test; |
43 import junit.framework.Test; |
45 import junit.framework.TestSuite; |
44 import junit.framework.TestSuite; |
46 |
45 |
47 public class SemaphoreTest extends JSR166TestCase { |
46 public class SemaphoreTest extends JSR166TestCase { |
48 public static void main(String[] args) { |
47 public static void main(String[] args) { |
99 */ |
98 */ |
100 void waitForQueuedThread(PublicSemaphore s, Thread t) { |
99 void waitForQueuedThread(PublicSemaphore s, Thread t) { |
101 long startTime = System.nanoTime(); |
100 long startTime = System.nanoTime(); |
102 while (!s.hasQueuedThread(t)) { |
101 while (!s.hasQueuedThread(t)) { |
103 if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
102 if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
104 throw new AssertionFailedError("timed out"); |
103 throw new AssertionError("timed out"); |
105 Thread.yield(); |
104 Thread.yield(); |
106 } |
105 } |
107 assertTrue(s.hasQueuedThreads()); |
106 assertTrue(s.hasQueuedThreads()); |
108 assertTrue(t.isAlive()); |
107 assertTrue(t.isAlive()); |
109 } |
108 } |
113 */ |
112 */ |
114 void waitForQueuedThreads(Semaphore s) { |
113 void waitForQueuedThreads(Semaphore s) { |
115 long startTime = System.nanoTime(); |
114 long startTime = System.nanoTime(); |
116 while (!s.hasQueuedThreads()) { |
115 while (!s.hasQueuedThreads()) { |
117 if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
116 if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
118 throw new AssertionFailedError("timed out"); |
117 throw new AssertionError("timed out"); |
119 Thread.yield(); |
118 Thread.yield(); |
120 } |
119 } |
121 } |
120 } |
122 |
121 |
123 enum AcquireMethod { |
122 enum AcquireMethod { |