summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/spi
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon/carbonado/spi')
-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;