Author: jacopoc
Date: Fri May 11 08:15:24 2012 New Revision: 1337054 URL: http://svn.apache.org/viewvc?rev=1337054&view=rev Log: Applied fix from trunk for revision: 1337046 === Based on review from Adam Heath, refactored/simplified the implementation of thread safe code using the parsedScripts object. Modified: ofbiz/branches/release12.04/ (props changed) ofbiz/branches/release12.04/applications/order/script/org/ofbiz/order/customer/CheckoutMapProcs.xml (props changed) ofbiz/branches/release12.04/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy (props changed) ofbiz/branches/release12.04/applications/product/script/org/ofbiz/product/test/InventoryTests.xml (props changed) ofbiz/branches/release12.04/framework/base/src/org/ofbiz/base/util/GroovyUtil.java ofbiz/branches/release12.04/framework/common/widget/HelpScreens.xml (props changed) ofbiz/branches/release12.04/framework/security/data/PasswordSecurityData.xml (props changed) ofbiz/branches/release12.04/specialpurpose/ebaystore/lib/ (props changed) ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/Facilities.groovy (props changed) ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductList.groovy (props changed) ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductStockTake.groovy (props changed) Propchange: ofbiz/branches/release12.04/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1337046 Propchange: ofbiz/branches/release12.04/applications/order/script/org/ofbiz/order/customer/CheckoutMapProcs.xml ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/applications/party/webapp/partymgr/WEB-INF/actions/party/PartyFinancialHistory.groovy ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/applications/product/script/org/ofbiz/product/test/InventoryTests.xml ('svn:mergeinfo' removed) Modified: ofbiz/branches/release12.04/framework/base/src/org/ofbiz/base/util/GroovyUtil.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/base/src/org/ofbiz/base/util/GroovyUtil.java?rev=1337054&r1=1337053&r2=1337054&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/base/src/org/ofbiz/base/util/GroovyUtil.java (original) +++ ofbiz/branches/release12.04/framework/base/src/org/ofbiz/base/util/GroovyUtil.java Fri May 11 08:15:24 2012 @@ -117,9 +117,7 @@ public class GroovyUtil { public static Class<?> getScriptClassFromLocation(String location, GroovyClassLoader groovyClassLoader) throws GeneralException { try { Class<?> scriptClass = null; - synchronized (parsedScripts) { - scriptClass = parsedScripts.get(location); - } + scriptClass = parsedScripts.get(location); if (scriptClass == null) { URL scriptUrl = FlexibleLocation.resolveLocation(location); if (scriptUrl == null) { @@ -130,17 +128,11 @@ public class GroovyUtil { } else { scriptClass = parseClass(scriptUrl.openStream(), location); } - synchronized (parsedScripts) { - Class<?> scriptClassCached = parsedScripts.get(location); - if (scriptClassCached == null) { - if (Debug.verboseOn()) { - Debug.logVerbose("Caching Groovy script at: " + location, module); - } - parsedScripts.put(location, scriptClass); - } else { - scriptClass = scriptClassCached; - } + scriptClass = parsedScripts.putIfAbsent(location, scriptClass); + if (scriptClass == null && Debug.verboseOn()) { // putIfAbsent returns null if the class is added + Debug.logVerbose("Cached Groovy script at: " + location, module); } + scriptClass = parsedScripts.get(location); } return scriptClass; } catch (Exception e) { @@ -184,23 +176,14 @@ public class GroovyUtil { public static Object runScriptFromClasspath(String script, Map<String,Object> context) throws GeneralException { try { - Class<?> scriptClass = null; - synchronized (parsedScripts) { - parsedScripts.get(script); - } + Class<?> scriptClass = parsedScripts.get(script); if (scriptClass == null) { scriptClass = loadClass(script); - synchronized (parsedScripts) { - Class<?> scriptClassCached = parsedScripts.get(script); - if (scriptClassCached == null) { - if (Debug.verboseOn()) { - Debug.logVerbose("Caching Groovy script: " + script, module); - } - parsedScripts.put(script, scriptClass); - } else { - scriptClass = scriptClassCached; - } + scriptClass = parsedScripts.putIfAbsent(script, scriptClass); + if (scriptClass == null && Debug.verboseOn()) { // putIfAbsent returns null if the class is added + Debug.logVerbose("Cached Groovy script at: " + script, module); } + scriptClass = parsedScripts.get(script); } return InvokerHelper.createScript(scriptClass, getBinding(context)).run(); } catch (CompilationFailedException e) { Propchange: ofbiz/branches/release12.04/framework/common/widget/HelpScreens.xml ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/framework/security/data/PasswordSecurityData.xml ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/specialpurpose/ebaystore/lib/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk/specialpurpose/ebaystore/lib:r1337046 Propchange: ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/Facilities.groovy ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductList.groovy ('svn:mergeinfo' removed) Propchange: ofbiz/branches/release12.04/specialpurpose/hhfacility/webapp/hhfacility/WEB-INF/actions/ProductStockTake.groovy ('svn:mergeinfo' removed) |
Free forum by Nabble | Edit this page |