gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djkevi...@apache.org
Subject [3/5] gora git commit: Make batch arraylist thread safe
Date Sun, 10 Sep 2017 20:38:50 GMT
Make batch arraylist thread safe


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/2303e85c
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/2303e85c
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/2303e85c

Branch: refs/heads/master
Commit: 2303e85c5ba9e2aaa72b0e3ea88d589e312df104
Parents: 71a95b9
Author: Kevin Ratnasekera <djkevincr@yahoo.com>
Authored: Mon Sep 11 01:04:40 2017 +0530
Committer: Kevin Ratnasekera <djkevincr@yahoo.com>
Committed: Mon Sep 11 01:04:40 2017 +0530

----------------------------------------------------------------------
 .../org/apache/gora/orientdb/store/OrientDBStore.java  | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/2303e85c/gora-orientdb/src/main/java/org/apache/gora/orientdb/store/OrientDBStore.java
----------------------------------------------------------------------
diff --git a/gora-orientdb/src/main/java/org/apache/gora/orientdb/store/OrientDBStore.java
b/gora-orientdb/src/main/java/org/apache/gora/orientdb/store/OrientDBStore.java
index d0b901f..9561701 100644
--- a/gora-orientdb/src/main/java/org/apache/gora/orientdb/store/OrientDBStore.java
+++ b/gora-orientdb/src/main/java/org/apache/gora/orientdb/store/OrientDBStore.java
@@ -29,6 +29,8 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.TimeZone;
 import java.util.Locale;
 
@@ -80,7 +82,8 @@ public class OrientDBStore<K, T extends PersistentBase> extends DataStoreBase<K,
   private OrientDBMapping orientDBMapping;
   private OServerAdmin remoteServerAdmin;
   private OPartitionedDatabasePool connectionPool;
-  private List<ODocument> docBatch = new ArrayList<>();
+  private List<ODocument> docBatch = Collections.synchronizedList(new ArrayList<>());
+  private ReentrantLock flushLock = new ReentrantLock();
 
   /**
    * Initialize the OrientDB dataStore by {@link Properties} parameters.
@@ -248,8 +251,10 @@ public class OrientDBStore<K, T extends PersistentBase> extends
DataStoreBase<K,
         selectTx.close();
       }
     } else {
-      LOG.info("Ignored putting persistent bean {} in the store as it is neither "
-              + "new, neither dirty.", new Object[]{val});
+      if (LOG.isDebugEnabled()) {
+        LOG.info("Ignored putting persistent bean {} in the store as it is neither "
+                + "new, neither dirty.", new Object[]{val});
+      }
     }
   }
 
@@ -388,12 +393,14 @@ public class OrientDBStore<K, T extends PersistentBase> extends
DataStoreBase<K,
     ODatabaseDocumentTx updateTx = connectionPool.acquire();
     updateTx.activateOnCurrentThread();
     try {
+      flushLock.lock();
       for (ODocument document : docBatch) {
         updateTx.save(document);
       }
     } finally {
       updateTx.close();
       docBatch.clear();
+      flushLock.unlock();
     }
   }
 


Mime
View raw message