jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vijay s <vijay.sreekan...@gmail.com>
Subject Concurrent Node Modification using Locked utility class causes issues
Date Sat, 10 Feb 2007 00:23:59 GMT


I am building a small proof of concept for an authoring application using
JackRabbit and am load testing it and am having some issues with
concurrency. I am trying to add a large number of child nodes to the JCR
root node. Each node is getting added in its own session in its own thread.
I get an exception indicating that the root node (/) has been modified
outside the current call and cannot be modified again. 

The exception is similar to the problem discussed on this thread -->

I also read this thread and followed the steps to create a lockable
subfolder and used the Locked utility to lock the sub-folder and started
adding content. -->


I am able to get my application working with the Locked utility class, but I
believe the locking of the folder to add content is causing some issues when
I try to "concurrently" add many nodes to a single folder. 

Jackrabbit throws a random ItemNotFoundException after I add about 400 nodes
concurrently in 20 threads --> 

Once such an error happens in one of my threads, the rest of the threads get
stuck in some form of a deadlock and my server crashes. The crashes become
more frequent and detrimental as I increase the number of concurrent threds.


1) Is there any alternative to this locking procedure to add child nodes to
a node. Do we "have" to lock a parent node to add child nodes ? I have found
that I get better reliability when I do not use the Locked utility class,
but just synchronize the code in a way where only one session can add nodes
to a particular folder. I really do not want to single thread the
application. Any recommendations on a better approach will be really
appreciated. Any insights on this particular cause of the
ItemNotFoundException will also be helpful.

2) Also, are there any additional references to a "how-to" /
"best-practices" guide that I can use to design for efficient and reliable
multiuser / multithreaded access to the JCR Repository.


Code Snippet:

	public void addContent(final String nodeId, final String nodeType, final
Map properties) {
		System.out.println("Adding project "+nodeId);
		Session session = getSession(true);
		try {
			final Node folder = session.getRootNode().getNode("assemblies");
			Node child = null;
			if (!folder.hasNode(nodeId)) {
				Object retChild = new Locked() {
				     protected Object run(Node folder) throws RepositoryException {
				         Node c = folder.addNode(nodeId, nodeType != null ? nodeType
									: "nt:unstructured");
							for (Object key : properties.keySet()) {
								c.setProperty((String) key, (String) properties
				         return c;
				}.with(folder, false,100000);
					throw new RuntimeException("Exception occured when adding a node.
Please try again");
				} else {
					child = (Node)retChild;
				child = folder.getNode(nodeId);
				System.out.println("Added project "+child.getPath()+" successfully");
		} catch (InterruptedException ex) {
			throw new RuntimeException(ex);			
		} catch (RepositoryException ex) {
			throw convertJCRAccessException(ex);
		} finally {			

Exception Snippet:
org.springframework.dao.DataRetrievalFailureException: Item not found;
nested exception is javax.jcr.ItemNotFoundException:
	at ContentDaoImpl.addContent(ContentDaoImpl.java:44)
	at ContentServiceImpl.addNewProject(ContentServiceImpl.java:51)

View this message in context: http://www.nabble.com/Concurrent-Node-Modification-using-Locked-utility-class-causes-issues-tf3203627.html#a8896073
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.

View raw message