geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aging...@apache.org
Subject [geode] branch feature/GEODE-3781 updated: Made prepared statment cache thread safe. Now each thread has its own prepared statement cache.
Date Fri, 27 Oct 2017 18:26:51 GMT
This is an automated email from the ASF dual-hosted git repository.

agingade pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3781 by this push:
     new e23aa67  Made prepared statment cache thread safe. Now each thread has its own prepared
statement cache.
e23aa67 is described below

commit e23aa67ef93e8c83472c8ff2fa0e1944276b5c58
Author: Anil <agingade@pivotal.io>
AuthorDate: Fri Oct 27 11:24:48 2017 -0700

    Made prepared statment cache thread safe.
    Now each thread has its own prepared statement cache.
---
 .../org/apache/geode/connectors/jdbc/JDBCManager.java | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
index 7c7ecea..afc59b2 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
@@ -23,7 +23,9 @@ import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -40,6 +42,18 @@ public class JDBCManager {
 
   private final ConcurrentMap<String, String> tableToPrimaryKeyMap = new ConcurrentHashMap<>();
 
+  private final ThreadLocal<Map<StatementKey, PreparedStatement>> preparedStatementCache
=
+      new ThreadLocal<>();
+
+  private Map<StatementKey, PreparedStatement> getPreparedStatementCache() {
+    Map<StatementKey, PreparedStatement> result = preparedStatementCache.get();
+    if (result == null) {
+      result = new HashMap<>();
+      preparedStatementCache.set(result);
+    }
+    return result;
+  }
+
   JDBCManager(JDBCConfiguration config) {
     this.config = config;
   }
@@ -186,9 +200,6 @@ public class JDBCManager {
     return result;
   }
 
-  private final ConcurrentMap<StatementKey, PreparedStatement> preparedStatementCache
=
-      new ConcurrentHashMap<>();
-
   private static class StatementKey {
     private final int pdxTypeId;
     private final Operation operation;
@@ -232,7 +243,7 @@ public class JDBCManager {
     System.out.println("getPreparedStatement : " + pdxTypeId + "operation: " + operation
         + " columns: " + columnList);
     StatementKey key = new StatementKey(pdxTypeId, operation, tableName);
-    return preparedStatementCache.computeIfAbsent(key, k -> {
+    return getPreparedStatementCache().computeIfAbsent(key, k -> {
       String query = getQueryString(tableName, columnList, operation);
       System.out.println("query=" + query);
       Connection con = getConnection();

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message