Need to synchronize on the lock object before calling download() so that

we don't accidentally notify ourselves nigh-immediately (e.g., if things
are already entirely up to date) before we've begun waiting on the lock
object on the calling thread.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1601 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2002-07-22 23:19:23 +00:00
parent 71c7a488c9
commit 7d7624fc67
@@ -1,5 +1,5 @@
//
// $Id: ResourceManager.java,v 1.14 2002/07/19 20:12:23 shaper Exp $
// $Id: ResourceManager.java,v 1.15 2002/07/22 23:19:23 shaper Exp $
package com.threerings.resource;
@@ -215,8 +215,8 @@ public class ResourceManager
// create an object to wait on while the download takes place
final Object lock = new Object();
// pass the descriptors on to the download manager
dlmgr.download(dlist, true, new DownloadObserver() {
// create the observer that will notify us when all is finished
DownloadObserver obs = new DownloadObserver() {
public void resolvingDownloads () {
// nothing for now
}
@@ -239,17 +239,19 @@ public class ResourceManager
lock.notify();
}
}
});
};
try {
synchronized (lock) {
synchronized (lock) {
// pass the descriptors on to the download manager
dlmgr.download(dlist, true, obs);
try {
// block until the download has completed
lock.wait();
} catch (InterruptedException ie) {
Log.warning("Thread interrupted while waiting for download " +
"to complete [ie=" + ie + "].");
}
} catch (InterruptedException ie) {
Log.warning("Thread interrupted while waiting for download " +
"to complete [ie=" + ie + "].");
}
}