5 Replies Latest reply on Mar 9, 2012 4:01 AM by hchiorean

    ItemExistException due to conccurent access ?

    akrambenaissi

      Hi Modeshapers,

       

      I am writing a small client API to invoke modeshape publish methods. While doing some tests with a few threads trying to create some nested folders I a facing the following exception:

       

      javax.jcr.ItemExistsException: A node definition that allows same name siblings could not be found for the node "/{}MyDir/{}R[2]" in workspace "default"
      

       

      I am trying to create the following folders:

      R/S/T/U/V

      And my threads seems to do the follwing creation orders:

      R/S/T

      R/

      R/S/T/U/V

       

      Can anyone explain if this is an expected behaviour?

       

      Greetings

        • 1. Re: ItemExistException due to conccurent access ?
          hchiorean

          Hi,

           

          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.

          1 of 1 people found this helpful
          • 2. Re: ItemExistException due to conccurent access ?
            akrambenaissi

            Hi,

             

            Well, the point is that I am using different sessions for each thread.

            • 3. Re: ItemExistException due to conccurent access ?
              hchiorean

              can you pls post the test case

              • 4. Re: ItemExistException due to conccurent access ?
                akrambenaissi

                Hi Horia,

                 

                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.

                • 5. Re: ItemExistException due to conccurent access ?
                  hchiorean

                  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[1], root/A[2], root/A[3], 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.