[cvs] / jsr166 / src / test / tck / AbstractQueuedSynchronizerTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7, Fri Jan 2 21:06:38 2004 UTC revision 1.8, Sun Jan 4 00:57:21 2004 UTC
# Line 42  Line 42 
42                  return true;                  return true;
43              }              }
44    
45              public void checkConditionAccess(Thread thread, boolean waiting) {              public void checkConditionAccess(Thread thread) {
46                  if (getState() == 0) throw new IllegalMonitorStateException();                  if (getState() == 0) throw new IllegalMonitorStateException();
47              }              }
48    
# Line 52  Line 52 
52                  s.defaultReadObject();                  s.defaultReadObject();
53                  setState(0); // reset to unlocked state                  setState(0); // reset to unlocked state
54              }              }
55    
56          }          }
57    
58          private final Sync sync = new Sync();          private final Sync sync = new Sync();
# Line 71  Line 72 
72          public Condition newCondition() { return sync.newCondition(); }          public Condition newCondition() { return sync.newCondition(); }
73          public boolean isLocked() { return sync.isLocked(); }          public boolean isLocked() { return sync.isLocked(); }
74          public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }          public boolean hasQueuedThreads() { return sync.hasQueuedThreads(); }
75            public boolean hasContended() { return sync.hasContended(); }
76      }      }
77    
78      /**      /**
# Line 151  Line 153 
153          }          }
154      }      }
155    
156    
157        /**
158         * hasContended reports whether there has been contention
159         */
160        public void testhasContended() {
161            final Mutex lock = new Mutex();
162            Thread t1 = new Thread(new InterruptedLockRunnable(lock));
163            Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
164            try {
165                assertFalse(lock.hasContended());
166                lock.lock();
167                t1.start();
168                Thread.sleep(SHORT_DELAY_MS);
169                assertTrue(lock.hasContended());
170                t2.start();
171                Thread.sleep(SHORT_DELAY_MS);
172                assertTrue(lock.hasContended());
173                t1.interrupt();
174                Thread.sleep(SHORT_DELAY_MS);
175                assertTrue(lock.hasContended());
176                lock.unlock();
177                Thread.sleep(SHORT_DELAY_MS);
178                assertTrue(lock.hasContended());
179                t1.join();
180                t2.join();
181            } catch(Exception e){
182                unexpectedException();
183            }
184        }
185    
186      /**      /**
187       * timed tryLock is interruptible.       * timed tryLock is interruptible.
188       */       */

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8