我应该将GryoMapper声明为静态字段吗?

时间:2019-04-05 20:47:42

标签: gremlin tinkerpop tinkerpop3 tinkergraph

看下面的代码,它似乎是线程安全的。

https://github.com/apache/tinkerpop/blob/master/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java

希望像这样使用它

$filepath = '/tmp/output.csv';
$query = 'SELECT Name, Address, City FROM PERSONAL_DATA WHERE Name LIKE \'A%\' INTO OUTFILE \'' . $filepath . '\' FIELDS TERMINATED BY \',\' OPTIONALLY ENCLOSED BY \'"\' LINES TERMINATED BY \'\r\n\'';
$result = mysqli_query($connection, $query) or die (mysqli_error());

代替

class Foo {
    private static final GryoMapper MAPPER = GryoMapper.build().create();
}

1 个答案:

答案 0 :(得分:1)

Gryo基于not thread-safe的Kryo。 GryoMapper基本上只是Kryo实例的构建器,这意味着您应该能够在没有static声明的情况下将其初始化为成员变量。只需确保从Kryo生成的GryoMapper实例不会被提供的Kryo链接中所述的多个线程同时访问。