191 } |
191 } |
192 static class CheckerThread extends Thread { |
192 static class CheckerThread extends Thread { |
193 public CheckerThread() { |
193 public CheckerThread() { |
194 super("CheckerThread"); |
194 super("CheckerThread"); |
195 } |
195 } |
|
196 |
|
197 private void waitForState(Thread.State state) { |
|
198 thrsync.waitForSignal(); |
|
199 while (waiter.getState() != state) { |
|
200 goSleep(10); |
|
201 } |
|
202 } |
|
203 |
196 public void run() { |
204 public void run() { |
197 synchronized (ready) { |
205 synchronized (ready) { |
198 // wait until WaitingThread about to wait for objC |
206 // wait until WaitingThread about to wait for objC |
199 thrsync.waitForSignal(); |
207 waitForState(Thread.State.WAITING); |
200 |
|
201 int retryCount = 0; |
|
202 while (waiter.getState() != Thread.State.WAITING |
|
203 && retryCount++ < 500) { |
|
204 goSleep(100); |
|
205 } |
|
206 checkBlockedObject(waiter, objC, null, Thread.State.WAITING); |
208 checkBlockedObject(waiter, objC, null, Thread.State.WAITING); |
207 |
209 |
208 synchronized (objC) { |
210 synchronized (objC) { |
209 objC.notify(); |
211 objC.notify(); |
210 } |
212 } |
211 |
213 |
212 // wait for waiter thread to about to enter |
214 // wait for waiter thread to about to enter |
213 // synchronized object ready. |
215 // synchronized object ready. |
214 thrsync.waitForSignal(); |
216 waitForState(Thread.State.BLOCKED); |
215 // give chance for waiter thread to get blocked on |
|
216 // object ready. |
|
217 goSleep(50); |
|
218 checkBlockedObject(waiter, ready, this, Thread.State.BLOCKED); |
217 checkBlockedObject(waiter, ready, this, Thread.State.BLOCKED); |
219 } |
218 } |
220 |
219 |
221 // wait for signal from waiting thread that it is about |
220 // wait for signal from waiting thread that it is about |
222 // wait for objC. |
221 // wait for objC. |
223 thrsync.waitForSignal(); |
222 waitForState(Thread.State.WAITING); |
224 synchronized(objC) { |
223 synchronized(objC) { |
225 checkBlockedObject(waiter, objC, Thread.currentThread(), Thread.State.WAITING); |
224 checkBlockedObject(waiter, objC, Thread.currentThread(), Thread.State.WAITING); |
226 objC.notify(); |
225 objC.notify(); |
227 } |
226 } |
228 |
227 |