You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2012/11/08 21:32:36 UTC

Fwd: svn commit: r1407132 - /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java

Hi guys,

in fact the implementation of the method can be throw new DontCallIt();

the lazyvalidator is used only when the
validatorFactory.usingContext().getValidator() call failed at startup

i added it initially just to let apps to provide a bval implementation in
the webapp and override our provided implementation (case we get with
grails apps for instance) - otherwise a tck test fails because a validator
factory just throw exceptions.

so IMO the implementation is not that much important.

any other idea to manage this case can be fine too


*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*




---------- Forwarded message ----------
From: <an...@apache.org>
Date: 2012/11/8
Subject: svn commit: r1407132 -
/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java
To: commits@openejb.apache.org


Author: andygumbrecht
Date: Thu Nov  8 15:32:44 2012
New Revision: 1407132

URL: http://svn.apache.org/viewvc?rev=1407132&view=rev
Log:
Not sure what the issue is but try this - IMHO much better for internal
synchronization.

Modified:

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java

Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java?rev=1407132&r1=1407131&r2=1407132&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/LazyValidator.java
Thu Nov  8 15:32:44 2012
@@ -20,10 +20,13 @@ import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.concurrent.locks.ReentrantLock;

 public class LazyValidator implements InvocationHandler {
+
+    private final ReentrantLock lock = new ReentrantLock();
     private final ValidatorFactory factory;
-    private volatile Validator validator = null;
+    private Validator validator = null;

     public LazyValidator(final ValidatorFactory factory) {
         this.factory = factory;
@@ -31,13 +34,21 @@ public class LazyValidator implements In

     @Override
     public Object invoke(final Object proxy, final Method method, final
Object[] args) throws Throwable {
+
         if (validator == null) {
-            synchronized (this) {
+
+            final ReentrantLock l = lock;
+            l.lock();
+
+            try {
                 if (validator == null) {
                     validator = factory.usingContext().getValidator();
                 }
+            } finally {
+                l.unlock();
             }
         }
+
         return method.invoke(validator, args);
     }
 }