[concurrency-interest]

Bill Pugh pugh at cs.umd.edu
Tue Oct 11 20:37:55 EDT 2005


The code below is broken.

For one thing, if the releaseMutex call occurs before the call to   
occurs before the
call to waitForResponse, the signal will be missed.

Also, await is allowed to return spuriously, so waitForResponse might  
return
even though no signal or timeout has occurred.

Use the boolean variable.

     Bill

On Oct 10, 2005, at 5:55 PM, Bhasin, Vishal wrote:

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


More information about the Concurrency-interest mailing list