diff options
author | timofeyb <timofeyb@google.com> | 2015-04-20 12:45:07 -0700 |
---|---|---|
committer | Sam Berlin <sameb@google.com> | 2015-04-21 09:37:16 -0400 |
commit | 5e6c93348c4250012801b6e41753789d760f06e4 (patch) | |
tree | 604e25005690d696b2a7ee8ac39273aca98af3b4 /core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java | |
parent | 6c85843a85100c01992a1f3c6a16bb9270055d84 (diff) | |
download | guice-5e6c93348c4250012801b6e41753789d760f06e4.tar.gz |
Implement more granular locks for a Singleton scope in Guice.
Now when you can create two independent singletons using
the same injector in different threads.
This make it easy to create scopes creating singletons using
thread pools with all the concurrency being done by Guice.
As a nice side effect Singleton scope is no longer treated
specially in Guice codebase.
The obvious problem to solve is potential deadlocks:
A requires B, B requires C, C requires A where all are
singletons and all are created simultaneously.
It's impossible to detect this deadlock using information
within one thread, so we have to have a shared storage.
An idea is to have a map of creators' locks and a map
of which threads are waiting for other singletons to be created.
Using this information circular dependencies are trivially
discovered within O(N) where N is a number of concurrent threads.
Important to not that no other deadlock scenarios within
Guice code is introduced as Guice does not expose any
other scopes that can span several threads.
Now it would be possible for
client code to deadlock on itself with two lazy singletons
calling each other's providers during creation.
This is deemed as a non-issue as it is up to the client
to write a thread-safe code.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=91610630
Diffstat (limited to 'core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java')
-rw-r--r-- | core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java b/core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java index b534f897..c02c70ea 100644 --- a/core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java +++ b/core/src/com/google/inject/internal/InternalFactoryToInitializableAdapter.java @@ -34,16 +34,15 @@ final class InternalFactoryToInitializableAdapter<T> extends ProviderInternalFac public InternalFactoryToInitializableAdapter( Initializable<? extends javax.inject.Provider<? extends T>> initializable, - Object source, boolean allowProxy, - ProvisionListenerStackCallback<T> provisionCallback) { - super(source, allowProxy); + Object source, ProvisionListenerStackCallback<T> provisionCallback) { + super(source); this.provisionCallback = checkNotNull(provisionCallback, "provisionCallback"); this.initializable = checkNotNull(initializable, "provider"); } public T get(Errors errors, InternalContext context, Dependency<?> dependency, boolean linked) throws ErrorsException { - return circularGet(initializable.get(errors), errors, context, dependency, linked, + return circularGet(initializable.get(errors), errors, context, dependency, provisionCallback); } |