summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-11-11 00:43:33 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-11-11 00:43:33 +0000
commit6a60d902b86ea0d983338195314a3344efd60cd0 (patch)
treefbd9ee23271ecc571ceaa8e0b04f35ea10176982 /src/main/java/com/amazon/carbonado
parent79f93ccdb4fb0648df4379a701fd3a9cc8bef622 (diff)
Fixed deadlock when using unsupported Storage for the first time.
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-rw-r--r--src/main/java/com/amazon/carbonado/spi/StorageCollection.java57
1 files changed, 32 insertions, 25 deletions
diff --git a/src/main/java/com/amazon/carbonado/spi/StorageCollection.java b/src/main/java/com/amazon/carbonado/spi/StorageCollection.java
index f0d38ad..45ab6f5 100644
--- a/src/main/java/com/amazon/carbonado/spi/StorageCollection.java
+++ b/src/main/java/com/amazon/carbonado/spi/StorageCollection.java
@@ -70,35 +70,42 @@ public abstract class StorageCollection {
}
}
- synchronized (lock) {
- // Check storage map again before creating new storage.
- while (true) {
- storage = mStorageMap.get(type);
- if (storage != null) {
- return storage;
- }
- if (doCreate) {
- break;
- }
- try {
- lock.wait();
- } catch (InterruptedException e) {
- throw new RepositoryException("Interrupted");
- }
- }
+ if (Thread.holdsLock(lock)) {
+ throw new IllegalStateException
+ ("Recursively trying to create storage for type: " + type);
+ }
- // Examine and throw exception early if there is a problem.
- StorableIntrospector.examine(type);
+ try {
+ synchronized (lock) {
+ // Check storage map again before creating new storage.
+ while (true) {
+ storage = mStorageMap.get(type);
+ if (storage != null) {
+ return storage;
+ }
+ if (doCreate) {
+ break;
+ }
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ throw new RepositoryException("Interrupted");
+ }
+ }
- storage = createStorage(type);
+ // Examine and throw exception early if there is a problem.
+ StorableIntrospector.examine(type);
- mStorageMap.put(type, storage);
- lock.notifyAll();
- }
+ storage = createStorage(type);
- // Storable type lock no longer needed.
- synchronized (mStorableTypeLockMap) {
- mStorableTypeLockMap.remove(type);
+ mStorageMap.put(type, storage);
+ lock.notifyAll();
+ }
+ } finally {
+ // Storable type lock no longer needed.
+ synchronized (mStorableTypeLockMap) {
+ mStorableTypeLockMap.remove(type);
+ }
}
return storage;