[concurrency-interest] dl.util.concurrent.BoundedBuffer.offer

Jean Morissette jmorissette666@hotmail.com
Wed, 01 Dec 2004 23:50:39 -0500


Hi,
Is there a reason to have the line
long waitTime = msecs;
in EDU.oswego.cs.dl.util.concurrent.BoundedBuffer.offer?
Why don't use 'msecs' directly?
Thanks

public boolean offer(Object x, long msecs) throws InterruptedException {
    if (x == null) throw new IllegalArgumentException();
    if (Thread.interrupted()) throw new InterruptedException();

    synchronized (putMonitor_) {
      long start = (msecs <= 0) ? 0 : System.currentTimeMillis();
      long waitTime = msecs;   //////////// Why ???
      while (emptySlots_ <= 0) {
        if (waitTime <= 0) return false;
        try {
          putMonitor_.wait(waitTime);
        } catch (InterruptedException ex) {
          putMonitor_.notify();
          throw ex;
        }
        waitTime = msecs - (System.currentTimeMillis() - start);
      }
      insert(x);
    }
    incUsedSlots();
    return true;
  }