Author: oskutka(a)redhat.com
Date: 2010-07-21 08:35:37 -0400 (Wed, 21 Jul 2010)
New Revision: 13462
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/Component.java
Log:
JBSEAM-2419 Narrowed locked block not to cause JBSEAM-4669
Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/Component.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/Component.java 2010-07-21 12:04:11
UTC (rev 13461)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/Component.java 2010-07-21 12:35:37
UTC (rev 13462)
@@ -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;
@@ -2051,7 +2054,6 @@
return getInstanceFromFactory(name, null);
}
- // JBSEAM-4669: Removed the "synchronized" keyword
private static Object getInstanceFromFactory(String name, ScopeType scope)
{
Init init = Init.instance();
@@ -2061,13 +2063,6 @@
}
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
Show replies by date