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

标签 java titan tinkerpop3

我用 spring boot 构建了一个网络服务。我使用 titan graph 作为跨 Web 服务访问的单例。因此,如果对 web 服务有多个请求,web 服务器将生成线程来处理请求,并且 titan graph 将在这些线程中使用。这种方法有什么问题吗?我使用 titan graph 1.0.0 和 tinkerpop 3.0.1-incubating。所以 titan graph 对我来说很新,我不知道在多线程中使用 titan graph 是否有任何冲突。如果这种方法有问题,那么在多线程中使用 titan graph 的最佳实践是什么?感谢您的帮助。

最佳答案

是的,去吧。如果您使用的是 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.

如果您使用的库可能跨多个线程承载单个概念性事务,例如,这可能会更安全。通过使用 deferred 或 promises。

关于java - 在多线程中使用 titan graph 的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975195/

相关文章:

apache-spark - 为 Spark 集群和 Cassandra 设置和配置 Titan

java - 如何在spring controller图片/视频中检测上传的文件类型

java - 线程中的异常 "main"java.sql.SQLException : Access denied for user '' @'localhost' (using password: NO)

java - Gradle依赖项未列出本地maven jar的依赖项

java - 在 Google App Engine 中存储旋转/翻转图像

graph - 如何在 Gremlin Server ( Titan 1.0) 中更新 Vertex 的值

titan - 在TinkerPop中next()意味着什么

graph-databases - Amazon Neptune - 使用 BothE() 时,不等于谓词不适用于边缘标签

java - titan 图数据库中并发更新的问题

java - 我可以从此 GraphTraversal 中获取顶点而不是元素吗?