繁体   English   中英

Titan中的多线程抛出异常

[英]Multithreading in Titan throws exception

我正在泰坦创建具有多个线程的顶点。 这是我的代码

尝试连接到Titan,指定架构,然后添加顶点。

g = TitanFactory.open("/conf/titan-cassandra.properties");
TitanManagement mgmt = g.getManagementSystem();
final PropertyKey userid = mgmt.makePropertyKey("userid").dataType(Integer.class).make();
TitanGraphIndex namei = mgmt.buildIndex("userid",Vertex.class).addKey(userid).unique().buildCompositeIndex();
mgmt.setConsistency(namei, ConsistencyModifier.LOCK);
mgmt.commit();

然后我在调用一个函数来添加顶点

多线程访问函数Add Vertex,该函数带有输入参数-随机生成的唯一数字(entityPK)

tx1 = g.newTransaction();
Vertex user_ver = tx1.addVertexWithLabel("user");
user_ver.setProperty("userid",entityPK);
//Adding other properties for vertex
tx1.commit();`

我读到该异常是由于未指定LOCK而引发的。 但是即使指定了LOCK,也会引发异常。

com.thinkaurelius.titan.core.TitanException:由于持久性期间发生异常而无法提交事务

如果此代码:

tx1 = g.newTransaction();
Vertex user_ver = tx1.addVertexWithLabel("user");
user_ver.setProperty("userid",entityPK);
//Adding other properties for vertex
tx1.commit();

是在您的addVertex函数内部,并且有多个线程正在调用addVertex ,我认为您使用的newTransaction不太正确。 这就创建了所谓的“线程事务”。 线程事务是其中多个线程作用于SAME事务的事务。 在您的用法中,每个线程都在创建自己的DIFFERENT事务。 根据您的描述,我会说正确的方法是使addVertex为:

Vertex user_ver = g.addVertexWithLabel("user");
user_ver.setProperty("userid",entityPK);
//Adding other properties for vertex
g.commit();

我还将考虑放弃锁定(除非您需要它)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM