jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Micah Whitacre <mkwhita...@gmail.com>
Subject Are Repository objects thread safe?
Date Thu, 29 Jan 2009 21:45:30 GMT
I've read in other mailing list posts that Session objects are not
thread safe however I was curious if Repository (specifically
RepositoryImpl) is a threadsafe object.  I'm trying to do some
concurrency testing for my code which is built on top of
JCR/Jackrabbit and was seeing some exceptions and wanted to insure I
didn't miss something simple like misusing an object.

The use case I'm testing with is in a single java 1.5 jvm using
jackrabbit-core 1.4.6 configured to hit a local derby database, I'm
simulating multiple threads trying to add a child node to the same
parent.  So the pseudo code for each thread is the following:

session = Repository.login()
parentNode = session.getNode();
parentNode.checkout()  <--this node is versioned
childNode = parentNode.addNode(<unique name>)
parentNode.setProperty(...) <-- sets a custom author property

There is only one RepositoryImpl object created in the JVM, so that
object is being shared across threads.  When this code executes I see
InvalidItemStateExceptions because of messages like:

has been modified externally
	at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1251)

Occasionally the message will also indicate it couldn't store
"predecessors" because of being modified externally since the parent
node is versioned.  If the exception is thrown then I will also get an
InvalidItemStateException thrown when trying to checkin the parent
node because it has pending changes.  I will also sometimes get the
InvalidItemStateException thrown when trying to checkout the parent
node with a message that the "isCheckedOut" property was modified

So the first question is this use case valid or am I violating the JCR
contract and using an object in an improper manner (e.g. should the
repository instance not be used across threads)?  Is there a
proper/recommended way to handle concurrent modification of the same

Also I'm curious, if there is only one repository instance, do I have
to retrieve the node again to make sure it is up to date or is calling
node.refresh(true) sufficient for me to do node.save() without getting
the InvalidItemStateException.

Thanks for your help,

View raw message