title: OrientDB multithread Concurrent Modification Exception and other errors
body: <p>I am writing an application that writes data to a graph on orientDB (v 2.2.3) this graph is something like the following:
  <a href="https://i.stack.imgur.com/rBQzi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rBQzi.png" alt="enter image description here"></a></p>
  
  <p>I have threads that add vertices to C vertices each C vertex has an independent thread which is responsible add D vertexes with there edges.</p>
  
  <p>Each thread is working on a separate transaction, I have been getting various errors and exception like the following:</p>
  
  <pre><code>com.orientechnologies.orient.core.exception.OStorageException: Error on commit
  at      com.orientechnologies.orient.client.remote.OStorageRemote.baseNetworkOperation(OStorageRemote.java:253)
  at com.orientechnologies.orient.client.remote.OStorageRemote.networkOperation(OStorageRemote.java:189)
  at com.orientechnologies.orient.client.remote.OStorageRemote.commit(OStorageRemote.java:1271)
  at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:549)
  at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:109)
  at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2665)
  at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2634)
  at com.tinkerpop.blueprints.impls.orient.OrientTransactionalGraph.commit(OrientTransactionalGraph.java:175)
  at JSONManager$.commitGrap2(JSONManager.scala:371)
  at JSONManager$$anonfun$main$2$$anon$1.run(JSONManager.scala:87)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at java.lang.Thread.run(Thread.java:745)
   .....
  Caused by: java.util.ConcurrentModificationException
  at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:711)
  at java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:739)
  at com.orientechnologies.orient.client.remote.OStorageRemote$28.execute(OStorageRemote.java:1284)
  at com.orientechnologies.orient.client.remote.OStorageRemote$28.execute(OStorageRemote.java:1271)
  at com.orientechnologies.orient.client.remote.OStorageRemote$2.execute(OStorageRemote.java:192)
  at com.orientechnologies.orient.client.remote.OStorageRemote.baseNetworkOperation(OStorageRemote.java:224)
  ... 12 more
  </code></pre>
  
  <p>UPDATE code:</p>
  
  <pre><code>    val t: Runnable = new Runnable {
      override def run(): Unit = {
        graph = factory.getTx
        saveDUnits(dUnit, graph)
        commitGrap(graph)
        graph.shutdown()
      }
    };
    pool.execute(t)
  
  def commitGrap(graph: OrientGraph): Unit = {
  var retryCount = 0
  while (retryCount &lt; 10) {
    try {
      graph.commit()
      retryCount = 11
    } catch {
      case e: Exception =&gt; println("Commit Error")
        e.printStackTrace()
        var sleepTime = 50
        if (retryCount &gt; 5) {
          sleepTime = 6000
        }
        Thread.sleep(sleepTime);
    } 
    retryCount = retryCount + 1
  }
  </code></pre>
  
  <p>}</p>