有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在多线程中使用titan graph的最佳实践是什么?

我用spring boot构建了一个web服务。我使用titan graph作为通过web服务访问的单例。所以,在多个web服务请求的情况下,web服务器将生成线程来处理请求,并在这些线程中使用titan graph。这种方法有什么问题吗?我使用titan graph 1.0.0和tinkerpop 3.0.1-孵化。所以titan graph对我来说是很新的,我不知道在多线程中使用titan graph是否有冲突。如果这种方法有问题,那么在多线程中使用titan graph的最佳实践是什么?谢谢你的帮助


共 (1) 个答案

  1. # 1 楼答案

    是的,去吧。如果您使用的是Titan,请务必阅读multi-threaded transactions上的文档

    With Blueprints' default transaction handling, each thread automatically opens its own transaction against the graph database. To open a thread-independent transaction, use the newTransaction() method. The newTransaction() method returns a new TransactionalGraph object that represents this newly opened transaction. The graph object tx supports all of the methods that the original graph did, but does so without opening new transactions for each thread. This allows us to start multiple threads which all work concurrently in the same transaction and one of which finally commits the transaction when all threads have completed their work.

    如果您使用的库可能跨多个线程承载单个概念事务,例如通过使用延迟或承诺,那么这可能会更安全