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; } } }
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; } } }