Hi Christian,
I have setup a stress test to access the same DB in parallel. I have only one call to the Context constructor and using that same Context instance for all executions.
I still get this exception:
Caused by: java.nio.channels.OverlappingFileLockException
at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1108)
at org.basex.io.random.TableDiskAccess.lock(TableDiskAccess.java:139)
at org.basex.data.DiskData.startUpdate(DiskData.java:207)
at org.basex.query.up.ContextModifier.apply(ContextModifier.java:131)
at org.basex.query.up.Updates.apply(Updates.java:157)
at org.basex.query.QueryContext.iter(QueryContext.java:351)
at org.basex.query.QueryProcessor.value(QueryProcessor.java:101)

I am accessing the returned elements (of the queries) via a Value.iter() iterator.
The queries returns a sequence of 100 elements.

Each access to the DB has its own subtree.
I.e. if "user 1" accesses the DB, then he only accesses the subtree assigned to him.

This is the DB tree structure:
MyDB
+ users/usr1.xml/container
+ users/usr2.xml/container
+ ...
+ users/usrN.xml/container

Are iterators also thread-safe?
If not, what can I use instead?

(Standalone unit test will follow.)

2016-10-06 20:07 GMT+02:00 Christian GrĂ¼n <christian.gruen@gmail.com>:
> I mean, once I have the Context object and opened a database, is it safe to
> access (read/write) it from multiple threads?

It depends on how you do it ;) If you call Command.execute() with the
same Context instance, you should be safe.