OrientDB多线程并发修改异常和其他错误

时间:2016-06-27 10:39:43

标签: orientdb

我正在编写一个将数据写入orientDB(v 2.2.3)图表的应用程序,该图如下所示: enter image description here

我有将顶点添加到C顶点的线程每个C顶点都有一个独立的线程,负责在边缘添加D顶点。

每个线程正在处理一个单独的事务,我遇到了各种错误和异常,如下所示:

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

更新代码:

    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 < 10) {
  try {
    graph.commit()
    retryCount = 11
  } catch {
    case e: Exception => println("Commit Error")
      e.printStackTrace()
      var sleepTime = 50
      if (retryCount > 5) {
        sleepTime = 6000
      }
      Thread.sleep(sleepTime);
  } 
  retryCount = retryCount + 1
}

}

1 个答案:

答案 0 :(得分:1)

最后我发现了我所做的错误,问题在于创建OrientGraphFactory实例,非线程安全工厂的创建就像下面的那样

var factory: OrientGraphFactory = new OrientGraphFactory("remote:106.140.20.233/test", "root", "123")

线程安全工厂的创建方式如下:

var factory: OrientGraphFactory = new OrientGraphFactory("remote:106.140.20.233/test", "root", "123").setupPool(1, 20)

我错过了添加.setPool(1,20)

就是这样