0
public class a {
private static TitanGraph titanGraph = null;
static GraphTraversalSource traversalSource = null;
public static void main(String a[])
{
titanGraph = TitanFunctions.getTitanGraph();
traversalSource = titanGraph.traversal();
// Task to be executed by each thread
Runnable r = new Runnable() {
public void run() {
long ab = traversalSource.V().has("RequestJob", "RequestId", 203)
.has("JobLockStatus","F")
.property("JobLockStatus", "B").count().next();
titanGraph.tx().commit();
System.out.println("value: "+ab+" : " +Thread.currentThread().getName());
}
};
Thread t1 = new Thread(r, "T1");
Thread t2 = new Thread(r, "T2");
t1.start();
t2.start();
}}
在上面的程序并发更新,两个并发线程试图在value..from “F”更新到“B”为同一RequestId=203
。
看起来好像两个线程的状态值都是“F”并将其更新为B。 但我想只有一个线程应该将值从“F”更改为“B”。更新值后,我也使用commit()来保存更改。
如果任何线程将状态从“(F)ree”更改为“(B)usy”..并且其他线程应该看到更改后的值..(“B”)。
请帮我解决这个问题。问题与泰坦图形数据库
@ Filipe..It一个非常好的教程working..thank u为链接,并解释....多了一个疑问是..如果跨节点运行的进程..并且不止一个流程尝试改变状态。只有一个流程会改变'joblockstatus'。我怎样才能做到这一点?请帮助我。检查Titan数据库中的'ConsistencyModifier.Lock' ..但它不工作.. – User12345
只要上面的代码运行在单个JVM(它会),泰坦将处理最终的一致性本身。如[指定](http://s3.thinkaurelius.com/docs/titan/1.0.0/eventual-consistency.html)所指定的'ConsistencyModifier.Lock'是有用的,如果你想更确定你的唯一性约束。它减慢了提交速度,但确保了唯一的索引。 –