This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch helix-integration
in repository https://gitbox.apache.org/repos/asf/airavata.git

commit f51f1f16ff687768f7cfade2b92e66b84bd105d8
Author: dimuthu <dimuthu.upeks...@gmail.com>
AuthorDate: Mon Mar 5 23:08:52 2018 -0500

    Thread safe entity manager factory
---
 .../core/app/catalog/util/AppCatalogJPAUtils.java  | 61 ++++++++++++----------
 1 file changed, 33 insertions(+), 28 deletions(-)

diff --git 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
index 2efd419..4fd4685 100644
--- 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
+++ 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/util/AppCatalogJPAUtils.java
@@ -45,37 +45,42 @@ public class AppCatalogJPAUtils {
     @PersistenceContext(unitName = "appcatalog_data")
     private static EntityManager appCatEntityManager;
 
+    private static Object lock = new Object();
+
     public static EntityManager getEntityManager() throws 
ApplicationSettingsException {
-        if (factory == null) {
-            String connectionProperties = "DriverClassName=" + 
readServerProperties(APPCATALOG_JDBC_DRIVER) + "," +
-                    "Url=" + readServerProperties(APPCATALOG_JDBC_URL) + 
"?autoReconnect=true," +
-                    "Username=" + readServerProperties(APPCATALOG_JDBC_USER) + 
"," +
-                    "Password=" + readServerProperties(APPCATALOG_JDBC_PWD) +
-                    ",validationQuery=" + 
readServerProperties(APPCATALOG_VALIDATION_QUERY);
-            System.out.println(connectionProperties);
-            Map<String, String> properties = new HashMap<String, String>();
-            properties.put("openjpa.ConnectionDriverName", 
"org.apache.commons.dbcp.BasicDataSource");
-            properties.put("openjpa.ConnectionProperties", 
connectionProperties);
-            properties.put("openjpa.DynamicEnhancementAgent", "true");
-            properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
-            // For app catalog, we don't need caching
+        synchronized (lock) {
+            if (factory == null) {
+                String connectionProperties = "DriverClassName=" + 
readServerProperties(APPCATALOG_JDBC_DRIVER) + "," +
+                        "Url=" + readServerProperties(APPCATALOG_JDBC_URL) + 
"?autoReconnect=true," +
+                        "Username=" + 
readServerProperties(APPCATALOG_JDBC_USER) + "," +
+                        "Password=" + 
readServerProperties(APPCATALOG_JDBC_PWD) +
+                        ",validationQuery=" + 
readServerProperties(APPCATALOG_VALIDATION_QUERY);
+                System.out.println(connectionProperties);
+                Map<String, String> properties = new HashMap<String, String>();
+                properties.put("openjpa.ConnectionDriverName", 
"org.apache.commons.dbcp.BasicDataSource");
+                properties.put("openjpa.ConnectionProperties", 
connectionProperties);
+                properties.put("openjpa.DynamicEnhancementAgent", "true");
+                properties.put("openjpa.RuntimeUnenhancedClasses", 
"unsupported");
+                //properties.put("openjpa.Multithreaded", "true");
+                // For app catalog, we don't need caching
 //            properties.put("openjpa.DataCache","" + 
readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + 
Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", 
SoftReferenceSize=0)");
 //            properties.put("openjpa.QueryCache","" + 
readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + 
Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", 
SoftReferenceSize=0)");
-            properties.put("openjpa.RemoteCommitProvider", "sjvm");
-            properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, 
Tool=INFO, SQL=INFO");
-            properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
-            properties.put("openjpa.jdbc.QuerySQLCache", "false");
-            properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, 
MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
-            factory = 
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
-        }
-        // clear cache at entitymangerfactory level
-        if (factory.getCache() != null) {
-            factory.getCache().evictAll();
-        }
-        appCatEntityManager = factory.createEntityManager();
-        // clear the entitymanager cache
-        if (appCatEntityManager != null) {
-            appCatEntityManager.clear();
+                properties.put("openjpa.RemoteCommitProvider", "sjvm");
+                properties.put("openjpa.Log", "DefaultLevel=INFO, 
Runtime=INFO, Tool=INFO, SQL=INFO");
+                properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
+                properties.put("openjpa.jdbc.QuerySQLCache", "false");
+                properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, 
MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
+                factory = 
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+            }
+            // clear cache at entitymangerfactory level
+            if (factory.getCache() != null) {
+                factory.getCache().evictAll();
+            }
+            appCatEntityManager = factory.createEntityManager();
+            // clear the entitymanager cache
+            if (appCatEntityManager != null) {
+                appCatEntityManager.clear();
+            }
         }
         return appCatEntityManager;
     }

-- 
To stop receiving notification emails like this one, please contact
dimuthu...@apache.org.

Reply via email to