【问题标题】:Titan adding vertex using multi-threadsTitan使用多线程添加顶点
【发布时间】:2015-12-02 16:09:52
【问题描述】:

我正在使用 Titan 1 与 tinkerpop3 和 gremlin。

对于小型工作,我使用基本上是在做的线程:

myNode = g.V().has(somthing)
//some tests
newNode = graph.addVertex(someProperties)
g.V(myNode).addEdge(newNode)

在创建边缘期间,我得到了这个异常: java.lang.IllegalStateException:顶点或类型与此事务无关 [v[41025720]]

我知道我的 newNode (有点)不在我线程的事务中。 如何刷新事务范围,或将我的新节点添加到当前事务中?

谢谢

【问题讨论】:

    标签: titan gremlin tinkerpop


    【解决方案1】:

    首先,我建议阅读 Titan 文档的 chapter 9,它更详细地处理了交易。

    对于您的具体问题,您需要做的就是创建一个事务并让所有线程处理该事务。直接从文档中获取您需要的是:

    TitanGraph g = TitanFactory.open(CONFIG);
    TransactionalGraph tx = g.newTransaction();
    Thread[] threads = new Thread[10];
    for (int i=0;i<threads.length;i++) {
        threads[i]=new Thread(new DoSomething(tx));
        threads[i].start();
    }
    for (int i=0;i<threads.length;i++) threads[i].join();
    tx.commit();
    

    这将使所有线程都在同一个事务上工作,并可以访问相同的节点和边。

    如果不这样做,Titan 将自动为访问图的每个不同线程创建一个新事务。这意味着每个线程将使用不同的新节点、边缘等。 .

    DoSomething 示例

    DoSomething(TransactionalGraph tx){
        tx.addVertex();
    } 
    

    【讨论】:

      猜你喜欢
      • 2016-12-02
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      • 2016-05-26
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多