Skip to content
Permalink
Browse files
Fix the wait condition, no need to wait when already done or cancelled
  • Loading branch information
seelmann committed Jul 9, 2019
1 parent d51054d commit b9c3f3d8f8ac7e0955741f77a6ab5018fa263800
Showing 2 changed files with 13 additions and 7 deletions.
@@ -56,7 +56,7 @@ public synchronized void cancel()
{
// set the cancel flag first
cancelled = true;

// Notify the future
notifyAll();
}
@@ -68,7 +68,7 @@ public synchronized void cancel()
public synchronized void secured()
{
done = true;

notifyAll();
}

@@ -104,7 +104,7 @@ public synchronized Boolean get() throws InterruptedException, ExecutionExceptio
{
wait();
}

return done;
}

@@ -113,10 +113,15 @@ public synchronized Boolean get() throws InterruptedException, ExecutionExceptio
* {@inheritDoc}
*/
@Override
public synchronized Boolean get( long timeout, TimeUnit unit ) throws InterruptedException, ExecutionException, TimeoutException
public synchronized Boolean get( long timeout, TimeUnit unit )
throws InterruptedException, ExecutionException, TimeoutException
{
wait( unit.toMillis( timeout ) );

// no need to wait if already done or cancelled
if ( !done && !cancelled )
{
wait( unit.toMillis( timeout ) );
}

return done;
}

@@ -87,7 +87,8 @@ public synchronized R get() throws InterruptedException
@Override
public synchronized R get( long timeout, TimeUnit unit ) throws InterruptedException
{
while ( !done && !cancelled )
// no need to wait if already done or cancelled
if ( !done && !cancelled )
{
wait( unit.toMillis( timeout ) );
}

0 comments on commit b9c3f3d

Please sign in to comment.