Author: trong.tran
Date: 2011-01-04 02:51:30 -0500 (Tue, 04 Jan 2011)
New Revision: 5674
Modified:
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/config/Param.java
Log:
EXOGTN-223 Prevent to load concurrently several time the same webui parameter
Modified:
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/config/Param.java
===================================================================
---
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/config/Param.java 2011-01-04
07:41:46 UTC (rev 5673)
+++
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/config/Param.java 2011-01-04
07:51:30 UTC (rev 5674)
@@ -40,7 +40,7 @@
private String value;
- private transient Object object;
+ private transient volatile Object object;
public String getName()
{
@@ -64,54 +64,77 @@
public Object getMapXMLObject(WebuiRequestContext context) throws Exception
{
- if (object != null)
- return object;
- ResourceResolver resolver = context.getResourceResolver(value);
- InputStream is = resolver.getInputStream(value);
- object = XMLObject.getObject(is);
- is.close();
+ if (object == null)
+ {
+ synchronized (this)
+ {
+ if (object == null)
+ {
+ ResourceResolver resolver = context.getResourceResolver(value);
+ InputStream is = resolver.getInputStream(value);
+ object = XMLObject.getObject(is);
+ is.close();
+ }
+ }
+ }
return object;
}
- @SuppressWarnings("unchecked")
public Object getMapGroovyObject(WebuiRequestContext context) throws Exception
{
- try
+ if (object == null)
{
- if (object != null)
- return object;
- ResourceResolver resolver = context.getResourceResolver(value);
- InputStream is = resolver.getInputStream(value);
- //TODO if is == null throw an exception saying the it's impossible to find
the file
- Binding binding = new Binding();
- GroovyShell shell = new
GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
- object = shell.evaluate(is);
- is.close();
- return object;
+ synchronized (this)
+ {
+ if (object == null)
+ {
+ try
+ {
+ ResourceResolver resolver = context.getResourceResolver(value);
+ InputStream is = resolver.getInputStream(value);
+ //TODO if is == null throw an exception saying the it's impossible
to find the file
+ Binding binding = new Binding();
+ GroovyShell shell = new
GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
+ object = shell.evaluate(is);
+ is.close();
+ }
+ catch (Exception e)
+ {
+ log.error("A problem in the groovy script : " + value, e);
+ throw e;
+ }
+ }
+ }
}
- catch (Exception e)
- {
- log.error("A problem in the groovy script : " + value, e);
- throw e;
- }
+ return object;
}
public Object getFreshObject(WebuiRequestContext context) throws Exception
{
- try
+ if (object == null)
{
- ResourceResolver resolver = context.getResourceResolver(value);
- InputStream is = resolver.getInputStream(value);
- Binding binding = new Binding();
- GroovyShell shell = new
GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
- object = shell.evaluate(is);
- is.close();
- return object;
+ synchronized (this)
+ {
+ if (object == null)
+ {
+ try
+ {
+ ResourceResolver resolver = context.getResourceResolver(value);
+ InputStream is = resolver.getInputStream(value);
+ Binding binding = new Binding();
+ GroovyShell shell = new
GroovyShell(Thread.currentThread().getContextClassLoader(), binding);
+ object = shell.evaluate(is);
+ is.close();
+ return object;
+ }
+ catch (Exception e)
+ {
+ log.error("A problem in the groovy script : " + value, e);
+ throw e;
+ }
+ }
+ }
}
- catch (Exception e)
- {
- log.error("A problem in the groovy script : " + value, e);
- throw e;
- }
+ return object;
}
}
\ No newline at end of file