[concurrency-interest] java.util.concurrent.locks.Condition.await(1000, TIME.MILLISECONDS) issue

Bhasin, Vishal Vishal.Bhasin at sabre-holdings.com
Mon Oct 10 17:55:44 EDT 2005


I noticed that using java.util.concurrent.locks.Condition.await(1000,
TIME.MILLISECONDS) causes the application to hang for a few seconds
(9-10 secs) every so often while running a load test. However, this
doesn't happen when I use boolean and use
java.util.concurrent.locks.Condition.await() in a while loop until this
is set to false. I wonder if anyone has seen this before. 

This one causes the lag to happen -

public abstract class BaseSyncService
{

    /** Timeout for process method, default 10 seconds */
    protected int _timeOut = 10 * 1000;
    final Lock lock = new ReentrantLock();
    final Condition notDone  = lock.newCondition(); 

    protected void releaseMutex()
    {
        lock.lock();
        try {
          notDone.signalAll();
        } finally {
          lock.unlock();
        }
    }

    public Object waitForResponse(int timeout)
        throws InterruptedException
    {
        lock.lock();

        try {
              notDone.await(timeout, TimeUnit.MILLISECONDS);
          } finally {
            lock.unlock();
          }

          return responseObject;
    }
}


The following code works fine



public abstract class BaseSyncService
{

    final Lock lock = new ReentrantLock();
    final Condition notDone  = lock.newCondition(); 

    protected void releaseMutex()
    {
        lock.lock();
        try {
            waitFlag = false;
          notDone.signalAll();
        } finally {
          lock.unlock();
        }
    }

    boolean waitFlag = true;

    public Object waitForResponse(int timeout)
        throws InterruptedException
    {
        lock.lock();

        try {
            while(waitFlag)
            {
                notDone.await();
            }

          } finally {
            lock.unlock();
          }

          return responseObject;
    }
}

I'd appreciate any suggestions..

Thanks,

Vishal Bhasin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20051010/266da589/attachment.htm


More information about the Concurrency-interest mailing list