我想要遍历图中所有的"user“节点,并对它们执行一些操作。
问题是我有太多的“用户”节点,并且我不能在堆上容纳所有这些节点。
所以,做一些像这样的事情:
try (Transaction tx = graphDb.beginTx())
{
Iterator<Node> n_column = autoNodeIndex.get( "type", "user" );
while (n_column.hasNext()) {
//create relationship for node...
}
tx.success();
}会导致GC开销异常。
我如何将它拆分成几个事务,但在同一个迭代器上?
我考虑过嵌套事务,但手册上不这么说。嵌套事务将本地内存滚动到顶级事务。
发布于 2013-11-04 00:05:37
只需添加一个计数器,每50.000个节点提交并启动一个新事务。
Transaction tx = graphDb.beginTx();
Iterator<Node> n_column = autoNodeIndex.get( "type", "user" );
int counter=0;
while (n_column.hasNext()) {
//create relationship for node...
if (++counter % 50000 == 0) {
tx.success(); tx.close();
tx = graphDb.beginTx();
}
}
tx.success();
tx.close();https://stackoverflow.com/questions/19745725
复制相似问题