Author: manaRH
Date: 2010-07-13 11:07:49 -0400 (Tue, 13 Jul 2010)
New Revision: 13371
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java
Log:
JBPAPP-4577 - reduced locking for fixing deadlock
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java 2010-07-13
14:26:52 UTC (rev 13370)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/Component.java 2010-07-13
15:07:49 UTC (rev 13371)
@@ -50,6 +50,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.concurrent.locks.ReentrantLock;
import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler;
@@ -129,6 +130,8 @@
private static final LogProvider log = Logging.getLogProvider(Component.class);
+ static ReentrantLock factoryLock = new ReentrantLock();
+
private ComponentType type;
private String name;
private ScopeType scope;
@@ -2049,9 +2052,8 @@
public static Object getInstanceFromFactory(String name) {
return getInstanceFromFactory(name, null);
}
-
- private static synchronized Object getInstanceFromFactory(String name, ScopeType
scope)
+ private static Object getInstanceFromFactory(String name, ScopeType scope)
{
Init init = Init.instance();
if (init==null) //for unit tests, yew!
@@ -2060,14 +2062,7 @@
}
else
{
- // check whether there has been created an instance by another thread while
waiting for this function's lock
- if (scope != STATELESS) {
- Object value = (scope == null) ? Contexts.lookupInStatefulContexts(name) :
scope.getContext().get(name);
- if (value != null) {
- return value;
- }
- }
-
+
Init.FactoryMethod factoryMethod = init.getFactory(name);
Init.FactoryExpression methodBinding = init.getFactoryMethodExpression(name);
Init.FactoryExpression valueBinding = init.getFactoryValueExpression(name);
@@ -2084,14 +2079,32 @@
else if ( factoryMethod!=null && getOutScope( factoryMethod.getScope(),
factoryMethod.getComponent() ).isContextActive() )
{
Object factory = Component.getInstance(
factoryMethod.getComponent().getName(), true );
- if (factory==null)
+ factoryLock.lock();
+ try
{
- return null;
+ // check whether there has been created an instance by another thread
while waiting for this function's lock
+ if (scope != STATELESS)
+ {
+ Object value = (scope == null) ?
Contexts.lookupInStatefulContexts(name) : scope.getContext().get(name);
+ if (value != null)
+ {
+ return value;
+ }
+ }
+
+ if (factory==null)
+ {
+ return null;
+ }
+ else
+ {
+ Object result = factoryMethod.getComponent().callComponentMethod(
factory, factoryMethod.getMethod() );
+ return handleFactoryMethodResult( name, factoryMethod.getComponent(),
result, factoryMethod.getScope() );
+ }
}
- else
+ finally
{
- Object result = factoryMethod.getComponent().callComponentMethod( factory,
factoryMethod.getMethod() );
- return handleFactoryMethodResult( name, factoryMethod.getComponent(),
result, factoryMethod.getScope() );
+ factoryLock.unlock();
}
}
else