T
- the type of values returned through the iteratorspublic interface ResourceIterable<T> extends Iterable<T>
Iterable
whose iterators
have associated resources
that need to be released.
ResourceIterators
obtained inside a transaction are always
automatically released when the transaction is committed or rolled back. Outside a transaction,
you must ensure that all returned ResourceIterators are either fully exhausted,
or explicitly closed. Failure to ensure this may cause indefinitely blocking of write operations.
If you intend to exhaust the returned iterators, you can use conventional code as you would with a normal Iterable:
ResourceIterable<Object> iterable;
for ( Object item : iterable )
{
...
}
However, if your code might not exhaust the iterator, (run until Iterator.hasNext()
returns false
), ResourceIterator
provides you with a ResourceIterator.close()
method that
should be invoked to free its resources, by using a finally
-block, or try-with-resource.
ResourceIterable<Object> iterable;
ResourceIterator<Object> iterator = iterable.iterator();
try
{
while ( iterator.hasNext() )
{
Object item = iterator.next();
if ( ... )
{
return item; // iterator may not be exhausted.
}
}
}
finally
{
iterator.close();
}
ResourceIterator
,
Transaction
Modifier and Type | Method and Description |
---|---|
ResourceIterator<T> |
iterator()
Returns an
iterator with associated resources that must be managed. |
ResourceIterator<T> iterator()
iterator
with associated resources that must be managed.
Don't forget to either exhaust the returned iterator or call the
close method
on it.Copyright © 2002-2013 The Neo4j Graph Database Project. All Rights Reserved.