The exception is caused by the fact that nt:folder (which I'm assuming is the type of MyDir) does not allow SNS. The reason why this happens, is that the multi-threaded code causes the repository to try to add R multiple times to the same parent dir. Using the same JCR session from multiple threads is not thread-safe and could cause this to happen.
Sorry I did not manage to isolate precisely the case. And because it is using threads, it always hard to reproduce.
Anyway, here is the scenario:
I want to create a tree folder, /A/B/C/d :
To do so, I have let's say 3 threads, each thread has its own session and they are launched conccurently.
T1: has to create /A/B/C
T2: has to create /A/B
T3: has to create A
T1 : has to create the d file
I am using the same code as the rest client, and it seems that when a parent folder does not exist it is created.
So what happens if T1 creates A and B and C, when T3 comes to start ?
Hope this could be clearer.
In this case, the A nodes (for each thread) would be added as Same Name Siblings under the root node. In effect, this would give you root/A, root/A, root/A, when all 3 threads finish.
Reason for this behavior is that the type of the root node is "mode:root" which allows same name siblings.
So whenever you add multiple children with the same name to a parent (regardless whether multi-threaded or not) the type of the parent is key to whether SNS are allowed or not. If they aren't alllowed, you normally get the exception which you mentioned in the 1st post.