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

David Holmes dholmes at dltech.com.au
Tue Oct 11 19:54:29 EDT 2005


java.util.concurrent.locks.Condition.await(1000, TIME.MILLISECONDS)
issueVishal,

I'm not at all clear on exactly what you are reporting. If I understand you
right, the code that waits until the condition is signalled works fine, but
the code that uses a timeout (and which never actually checks for being
signalled) occasionally hangs for 9-10 seconds. Without seeing the code that
uses the BaseSyncService it is very hard to get an idea of what might be
happening. And I'm assuming that all else is "equal" when you run the two
different versions.

Can you post more code?

David Holmes


  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Bhasin,
Vishal
  Sent: Tuesday, 11 October 2005 7:56 AM
  To: Doug Lea; concurrency-interest at altair.cs.oswego.edu
  Subject: [concurrency-interest]
java.util.concurrent.locks.Condition.await(1000,TIME.MILLISECONDS) issue


  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/20051012/9353335d/attachment.htm


More information about the Concurrency-interest mailing list