Author: cschneider
Date: Mon Mar  6 21:41:47 2017
New Revision: 1785770

URL: http://svn.apache.org/viewvc?rev=1785770&view=rev
Log:
[ARIES-1689] Fix initialization

Modified:
    
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java

Modified: 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java?rev=1785770&r1=1785769&r2=1785770&view=diff
==============================================================================
--- 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
 (original)
+++ 
aries/trunk/jpa/jpa-blueprint/src/main/java/org/apache/aries/jpa/blueprint/impl/JpaInterceptor.java
 Mon Mar  6 21:41:47 2017
@@ -19,6 +19,7 @@
 package org.apache.aries.jpa.blueprint.impl;
 
 import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.persistence.EntityManager;
 import javax.persistence.spi.PersistenceUnitTransactionType;
@@ -39,11 +40,13 @@ public class JpaInterceptor implements I
     private BlueprintContainer container;
     private String coordinatorId;
     private String emId;
+    private AtomicBoolean initialized;
 
     public JpaInterceptor(BlueprintContainer container, String coordinatorId, 
String emId) {
         this.container = container;
         this.coordinatorId = coordinatorId;
         this.emId = emId;
+        this.initialized = new AtomicBoolean(false);
     }
 
     @Override
@@ -53,7 +56,7 @@ public class JpaInterceptor implements I
 
     @Override
     public Object preCall(ComponentMetadata cm, Method m, Object... 
parameters) throws Throwable {
-        if (coordinator == null || em == null) {
+        if (!initialized.get()) {
             initServices();
         }
         try {
@@ -71,7 +74,7 @@ public class JpaInterceptor implements I
     }
 
     private synchronized void initServices() {
-        if (coordinator == null || em == null) {
+        if (initialized.compareAndSet(false, true)) {
             coordinator = 
(Coordinator)container.getComponentInstance(coordinatorId);
             em = (EntityManager)container.getComponentInstance(emId);
         }


Reply via email to