我通过远程连接到 janusGraph
cluster = Cluster.build()
.addContactPoints(uri.split("\\|"))
.port(port)
.serializer(new GryoMessageSerializerV1d0(GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance())))
.maxConnectionPoolSize(poolSize)
.maxContentLength(10000000)
.create();
gts = AnonymousTraversalSource
.traversal()
.withRemote(DriverRemoteConnection.using(cluster));
Run Code Online (Sandbox Code Playgroud)
由于 gts 是线程安全的,我将 gts 保持在静态上下文中。每个线程使用相同的对象,并且没有一个线程通过调用 gts.close() 关闭 gts 每个线程运行查询,例如:
result = gts.V().has("foo","bar").valueMap().toList()
我不关闭 gts(graphTraversalSource) 不是由创建的 graphTraversal 对象gts.V()