EXTVAL-123: Improve performance (remarked by Gerhard)
git-svn-id: https://svn.apache.org/repos/asf/myfaces/extensions/validator/trunk@1057123 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValLifecycleWrapper.java b/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValLifecycleWrapper.java
index c6fd173..348c44d 100644
--- a/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValLifecycleWrapper.java
+++ b/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValLifecycleWrapper.java
@@ -29,6 +29,7 @@
/**
* Wrapper around a Lifecycle that initialise the ExtVal PhaseListeners before an execution of any
* phase (except the render view). Solution for the issue EXTVAL-123.
+ *
* @author Rudy De Busscher
* @author Gerard Petracek
* @since x.x.5
@@ -38,10 +39,11 @@
{
private Lifecycle wrapped;
+ private boolean initialized = false;
+
ExtValLifecycleWrapper(Lifecycle wrapped)
{
this.wrapped = wrapped;
-
}
public void addPhaseListener(PhaseListener phaseListener)
@@ -52,7 +54,10 @@
public void execute(FacesContext facesContext)
throws FacesException
{
- initializeExtVal();
+ if(!this.initialized)
+ {
+ initializeExtVal();
+ }
wrapped.execute(facesContext);
}
@@ -75,9 +80,9 @@
}
- private void initializeExtVal()
+ private synchronized void initializeExtVal()
{
-
+ //we don't need further checks - startup listeners are deregistered after the invocation.
for (PhaseListener currentPhaseListener : getPhaseListeners())
{
if (currentPhaseListener instanceof AbstractStartupListener)
@@ -85,6 +90,6 @@
currentPhaseListener.beforePhase(null);
}
}
+ this.initialized = true;
}
-
}