[ 
https://issues.apache.org/jira/browse/JCR-1939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12664816#action_12664816
 ] 

akil ajani commented on JCR-1939:
---------------------------------


Hi,
Please see my code for adding nodes into the jackrabbit by using threads in 
different session.

package com.cognizant.jackrabbit;

import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;

public class RepositoryDiffSession {

        /**
         * @param args
         */
        public void startAddingKnowledge(){
        Repository repository = null;
        Session jcrSession;

         try {
                repository = RepositoryFactory.getInstance("D:/Tomcat 
5.0/webapps/JCRTimeLine","login","D:/JCRTimeLine").getRepository();
                jcrSession = repository.login(new 
SimpleCredentials("userName","password".toCharArray()));
                Node rootNode = jcrSession.getRootNode();
                rootNode.addNode ("A");
                rootNode.save();
                final Session session1 = repository.login (new 
SimpleCredentials ("userName", "password".toCharArray()));
                final Session session2 = repository.login (new 
SimpleCredentials ("userName", "password".toCharArray()));
        
        Thread thread1 = new Thread (new Runnable()
        {
                public void run()
                {
                        try
                        {
                                addNodes ("A", session1, 0 , 500);
                        }
                        catch (RepositoryException ex)
                        {
                                throw new RuntimeException (ex);
                        }
                }
        });
        
        Thread thread2 = new Thread (new Runnable()
        {
                public void run()
                {
                        try
                        {
                                addNodes ("A", session2, 501 ,1000);
                            }
                            catch (RepositoryException ex)
                            {
                                    throw new RuntimeException (ex);
                            }
                    }
            });
        
            thread1.start();
            thread2.start();
                thread1.join();
                thread2.join();
                
                }catch (ItemExistsException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (PathNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (VersionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (ConstraintViolationException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (LockException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (RepositoryException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        private void addNodes (String parentName, Session session, int 
startIndex , int endIndex)
            throws RepositoryException
        {
            Node parentNode = session.getRootNode().getNode (parentName);
            for (int i = startIndex; i < endIndex; i++)
            {
                    String name = Integer.toString (i);
                    parentNode.addNode (name);
                    parentNode.save();
                    System.out.println("Document " + name + " added 
successfully...");
            } 
        }
        public static void main(String[] args) {
                RepositoryDiffSession repositoryDiffSession = new 
RepositoryDiffSession();
                repositoryDiffSession.startAddingKnowledge();
        }
}

I faced this exception

Exception in thread "Thread-10" java.lang.RuntimeException: 
javax.jcr.InvalidItemStateException: 7cc640a9-5dad-44c7-ae5a-90cfd37b87db has 
been modified externally
        at 
com.cognizant.jackrabbit.RepositoryDiffSession$1.run(RepositoryDiffSession.java:43)
        at java.lang.Thread.run(Thread.java:595)
Caused by: javax.jcr.InvalidItemStateException: 
7cc640a9-5dad-44c7-ae5a-90cfd37b87db has been modified externally
        at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1109)
        at 
com.cognizant.jackrabbit.RepositoryDiffSession.addNodes(RepositoryDiffSession.java:100)

the exception occurred is exactly similar with JCR-1359. Please help me to 
resolve this.




> If we threading to add nodes into the repository
> ------------------------------------------------
>
>                 Key: JCR-1939
>                 URL: https://issues.apache.org/jira/browse/JCR-1939
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>    Affects Versions: 1.5.0
>         Environment: Microsoft windows XP professional, 2GB ram
>            Reporter: akil ajani
>            Assignee: Jukka Zitting
>             Fix For: 1.5.0
>
>
> Senario 1: 
> we have a root node and it has 1 parent node. i am trying to add 600 nodes to 
> that parent node. so i have created 3 threads and each thread is adding 200 
> nodes. it works for some time and later on throws an exception
> java.util.ConcurrentModificationException
>       at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
>       at java.util.HashMap$ValueIterator.next(HashMap.java:817)
>       at 
> java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1010)
>       at 
> org.apache.jackrabbit.core.state.SessionItemStateManager.getDescendantTransientItemStates(SessionItemStateManager.java:376)
>       at 
> org.apache.jackrabbit.core.ItemImpl.getTransientStates(ItemImpl.java:361)
>       at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1079)
>       at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:849)
> some time it gets HANGED
> Scenario:2
> we have a root node and it has 2 parent node. i am trying to add 600 nodes to 
> eac parent node. so i have created 2 threads and each thread is adding 600 
> nodes to cach parent node. it works for some time and later on throws an 
> exception
> java.util.ConcurrentModificationException
>       at java.util.HashMap$HashIterator.nextEntry(HashMap.java:787)
>       at java.util.HashMap$ValueIterator.next(HashMap.java:817)
>       at 
> java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1010)
>       at 
> org.apache.jackrabbit.core.state.SessionItemStateManager.getDescendantTransientItemStates(SessionItemStateManager.java:376)
>       at 
> org.apache.jackrabbit.core.ItemImpl.getTransientStates(ItemImpl.java:361)
>       at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1079)
>       at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:849)
> some time it gets HANGED
> please help me to resolve this issue as soon as possible. i would be thankful 
> to you if you could provide me the solution for this as soon as possible

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to