Java seems to hang with increasing foreach loop. I can’t find anyone there with a similar problem, so maybe I’m just doing something wrong, but I can’t imagine what it is. I pull out a set of nodes from the Neo4J database and then repeat it. I do not change this set of nodes during the loop, but after a while it hangs. Here is the code that does this:
IndexHits<Node> usrs = users.get("Type", "User");
System.out.println("Operating on "+usrs.size()+" Users:");
for (Node u : usrs) {
System.out.print(".");
if (inUserBlacklist(u))
continue;
System.out.println("HA");
}
All that inUserBlacklist (u) does is check Node u for a given set of nodes to see if Node is part of the blacklist. This does not change anything about Node u.
Users are the Neo4J index, so calling get () on it should return an iterable IndexHits object. This foreach loop goes through the foreach loop 269,938 times. At the end of this iteration, he prints “HA,” but then he never prints another “.”. It just hangs at that moment, right before iteration 269 939. This puts it in a foreach loop lock. There should be 270012 iterations in total.
I noticed that my blacklist contains 74 items, each of which must coincide once during the passage of this cycle. 270.012 - 74 = 269.938, but this does not explain why it blocks. All I can understand is that the foreach loop increments the position on the iterator without increasing its counter when calling continue. Then he gets to the end of the set and has nothing more, but the counter believes that he is only at 269,938 out of 270,012.
- , foreach ?
EDIT:
, for ( 116):
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.FileDispatcher.pread0(Native Method)
at sun.nio.ch.FileDispatcher.pread(FileDispatcher.java:49)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:248)
at sun.nio.ch.IOUtil.read(IOUtil.java:224)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:663)
at org.neo4j.kernel.impl.nioneo.store.PersistenceRow.readPosition(PersistenceRow.java:91)
at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.acquire(PersistenceWindowPool.java:177)
at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.acquireWindow(CommonAbstractStore.java:559)
at org.neo4j.kernel.impl.nioneo.store.RelationshipStore.getChainRecord(RelationshipStore.java:349)
at org.neo4j.kernel.impl.nioneo.xa.ReadTransaction.getMoreRelationships(ReadTransaction.java:121)
at org.neo4j.kernel.impl.nioneo.xa.ReadTransaction.getMoreRelationships(ReadTransaction.java:104)
at org.neo4j.kernel.impl.persistence.PersistenceManager.getMoreRelationships(PersistenceManager.java:108)
at org.neo4j.kernel.impl.core.NodeManager.getMoreRelationships(NodeManager.java:666)
at org.neo4j.kernel.impl.core.NodeImpl.getMoreRelationships(NodeImpl.java:427)
- locked <0x77c9b4a0> (a org.neo4j.kernel.impl.core.NodeImpl)
at org.neo4j.kernel.impl.core.IntArrayIterator.fetchNextOrNull(IntArrayIterator.java:91)
at org.neo4j.kernel.impl.core.IntArrayIterator.fetchNextOrNull(IntArrayIterator.java:36)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)
at org.neo4j.kernel.impl.traversal.TraversalBranchImpl.next(TraversalBranchImpl.java:128)
at org.neo4j.kernel.PreorderBreadthFirstSelector.next(PreorderBreadthFirstSelector.java:48)
at org.neo4j.kernel.impl.traversal.TraverserImpl$TraverserIterator.fetchNextOrNull(TraverserImpl.java:127)
at org.neo4j.kernel.impl.traversal.TraverserImpl$TraverserIterator.fetchNextOrNull(TraverserImpl.java:94)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)
at org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
at NodePlacement.LoadFromNode(NodePlacement.java:116)
... , . . , - ?