- 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
This commit is contained in:
ray
2005-08-03 20:43:46 +00:00
parent e02258a053
commit 489e3a72c7
@@ -73,7 +73,7 @@ public class ServiceWaiter
/** /**
* Reset the service waiter so that it can be used again. * Reset the service waiter so that it can be used again.
*/ */
public void reset () public synchronized void reset ()
{ {
_success = 0; _success = 0;
_argument = null; _argument = null;
@@ -116,27 +116,31 @@ public class ServiceWaiter
* @return true if a success response was posted, false if a failure * @return true if a success response was posted, false if a failure
* repsonse was posted. * repsonse was posted.
*/ */
public synchronized boolean waitForResponse () public boolean waitForResponse ()
throws TimeoutException throws TimeoutException
{ {
while (_success == 0) { if (_success == 0) {
try { synchronized (this) {
// wait for the response, timing out after a while while (_success == 0) {
if (_timeout == NO_TIMEOUT) { try {
wait(); // wait for the response, timing out after a while
if (_timeout == NO_TIMEOUT) {
wait();
} else { } else {
wait(1000L * _timeout); 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
} }
} }