From 489e3a72c745f670db581f840a67b44703fece58 Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 3 Aug 2005 20:43:46 +0000 Subject: [PATCH] - synchronized the reset() method - avoid synchronization in waitForResponse() if possible. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1684 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/util/ServiceWaiter.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/ServiceWaiter.java b/projects/samskivert/src/java/com/samskivert/util/ServiceWaiter.java index 3ebf98c6..ffa3e81f 100644 --- a/projects/samskivert/src/java/com/samskivert/util/ServiceWaiter.java +++ b/projects/samskivert/src/java/com/samskivert/util/ServiceWaiter.java @@ -73,7 +73,7 @@ public class ServiceWaiter /** * Reset the service waiter so that it can be used again. */ - public void reset () + public synchronized void reset () { _success = 0; _argument = null; @@ -116,27 +116,31 @@ public class ServiceWaiter * @return true if a success response was posted, false if a failure * repsonse was posted. */ - public synchronized boolean waitForResponse () + public boolean waitForResponse () throws TimeoutException { - while (_success == 0) { - try { - // wait for the response, timing out after a while - if (_timeout == NO_TIMEOUT) { - wait(); + if (_success == 0) { + synchronized (this) { + while (_success == 0) { + try { + // wait for the response, timing out after a while + if (_timeout == NO_TIMEOUT) { + wait(); - } else { - wait(1000L * _timeout); + } else { + wait(1000L * _timeout); + } + + // if we get here without some sort of response, then + // we've timed out + if (_success == 0) { + throw new TimeoutException(); + } + + } catch (InterruptedException ie) { + // fall through and wait again + } } - - // if we get here without some sort of response, then - // we've timed out - if (_success == 0) { - throw new TimeoutException(); - } - - } catch (InterruptedException ie) { - // fall through and wait again } }