コード例 #1
0
 public void put(Object x) throws InterruptedException {
   if (x == null) throw new IllegalArgumentException();
   if (Thread.interrupted()) throw new InterruptedException();
   putGuard_.acquire();
   try {
     insert(x);
     takeGuard_.release();
   } catch (ClassCastException ex) {
     putGuard_.release();
     throw ex;
   }
 }
コード例 #2
0
 public Object take() throws InterruptedException {
   if (Thread.interrupted()) throw new InterruptedException();
   takeGuard_.acquire();
   try {
     Object x = extract();
     putGuard_.release();
     return x;
   } catch (ClassCastException ex) {
     takeGuard_.release();
     throw ex;
   }
 }
コード例 #3
0
 public Object poll(long msecs) throws InterruptedException {
   if (Thread.interrupted()) throw new InterruptedException();
   if (!takeGuard_.attempt(msecs)) return null;
   else {
     try {
       Object x = extract();
       putGuard_.release();
       return x;
     } catch (ClassCastException ex) {
       takeGuard_.release();
       throw ex;
     }
   }
 }
コード例 #4
0
 public boolean offer(Object x, long msecs) throws InterruptedException {
   if (x == null) throw new IllegalArgumentException();
   if (Thread.interrupted()) throw new InterruptedException();
   if (!putGuard_.attempt(msecs)) return false;
   else {
     try {
       insert(x);
       takeGuard_.release();
       return true;
     } catch (ClassCastException ex) {
       putGuard_.release();
       throw ex;
     }
   }
 }
コード例 #5
0
 /**
  * Return the number of elements in the buffer. This is only a snapshot value, that may change
  * immediately after returning.
  */
 public int size() {
   return (int) (takeGuard_.permits());
 }