You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by ge...@bt.com on 2010/01/15 14:02:15 UTC

Jackrabbit Multi Threading Issue

Hi

I'm using jackrabbit in a multi-threaded application.

I have used ThreadLocal to confine the Jackrabbit Session to a single
thread and see no issues executing simultaneous threads except the
following scenario:-

- I want to create one node of type "nt:folder" and then have child
nodes creating under it.
- I attempt to get the node (of type "nt:folder") first.
- If I receive PathNotFoundException, then I create the node (of type
"nt:folder") and save the session.
- Some threads create extra nodes of the same name although the node
exists?

I've tried quite a few synchronization strategies, but no success. I
haven't tried node locking.

Any help would be appreciated.

Regards


George Sibley

Re: Jackrabbit Multi Threading Issue

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

2010/1/16 george.sibley <ge...@bt.com>:
> How do I get the top level node to be created by the system?

I'd place it in the startup code of the application. I assume you
already have such code, e.g. to register node types that are required
for your application.

regards
 marcel

RE: Jackrabbit Multi Threading Issue

Posted by ge...@bt.com.
Hi Marcel

One thing I forgot to mention in the post is that I don't experience the same behaviour on the folder nodes created under those first level folder nodes. My bad.

So this could be the answer.

One thing though. How do I get the top level node to be created by the system? Sorry, still getting up to speed with jackrabbit.

Many thanks for your help.

regards 

George

-----Original Message-----
From: mreutegg@day.com [mailto:mreutegg@day.com] On Behalf Of Marcel Reutegger
Sent: 15 January 2010 21:28
To: dev
Subject: Re: Jackrabbit Multi Threading Issue

Hi,

the root node indeed allows same name sibling child nodes. I suggest you move everything one level down. something like:

root
       root-folder
              folder1
                      sub-folder1
                      content1
                              content2
                      sub-folder2
                      content1
                              content2
              folder2
                      ........

where root-folder is nt:folder and is created initially by the system.

regards
 marcel

On Fri, Jan 15, 2010 at 16:22,  <ge...@bt.com> wrote:
> Hi Marcel
>
> Many thanks for the reply.
>
> Sorry should've made things clearer.
>
> The "nt:folder" nodes are added to the root node. We then add further 
> "nt:folder" nodes hanging off these nodes, and then a mixture of other 
> nodes (e.g. "jcr:content"). E.g:-
>
> root
>        folder1
>                sub-folder1
>                content1
>                        content2
>                sub-folder2
>                content1
>                        content2
>        folder2
>                ........
>
> Regards
>
>
> George
> -----Original Message-----
> From: mreutegg@day.com [mailto:mreutegg@day.com] On Behalf Of Marcel 
> Reutegger
> Sent: 15 January 2010 14:46
> To: dev
> Subject: Re: Jackrabbit Multi Threading Issue
>
> Hi,
>
> On Fri, Jan 15, 2010 at 14:02,  <ge...@bt.com> wrote:
>> Hi
>>
>> I'm using jackrabbit in a multi-threaded application.
>>
>> I have used ThreadLocal to confine the Jackrabbit Session to a single 
>> thread and see no issues executing simultaneous threads except the 
>> following
>> scenario:-
>>
>> - I want to create one node of type "nt:folder" and then have child 
>> nodes creating under it.
>> - I attempt to get the node (of type "nt:folder") first.
>> - If I receive PathNotFoundException, then I create the node (of type
>> "nt:folder") and save the session.
>> - Some threads create extra nodes of the same name although the node
> exists?
>>
>> I've tried quite a few synchronization strategies, but no success. I 
>> haven't tried node locking.
>
> what's the type of the parent node where the threads will create 
> nt:folder nodes?
>
> it seems that the node type allows same name sibling child nodes.
>
> but even if you changed that you may run into another exception. after 
> trying to get a node and catching the PathNotFoundException, another 
> thread may have created the node meanwhile. so you probably have to 
> catch another exception: ItemExistException when trying to add the 
> folder node and saving it. that's kind of ugly, but will probably work.
> otherwise you should use locking.
>
> regards
>  marcel
>
>> Any help would be appreciated.
>>
>> Regards
>>
>> George Sibley
>

Re: Jackrabbit Multi Threading Issue

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

the root node indeed allows same name sibling child nodes. I suggest
you move everything one level down. something like:

root
       root-folder
              folder1
                      sub-folder1
                      content1
                              content2
                      sub-folder2
                      content1
                              content2
              folder2
                      ........

where root-folder is nt:folder and is created initially by the system.

regards
 marcel

On Fri, Jan 15, 2010 at 16:22,  <ge...@bt.com> wrote:
> Hi Marcel
>
> Many thanks for the reply.
>
> Sorry should've made things clearer.
>
> The "nt:folder" nodes are added to the root node. We then add further
> "nt:folder" nodes hanging off these nodes, and then a mixture of other
> nodes (e.g. "jcr:content"). E.g:-
>
> root
>        folder1
>                sub-folder1
>                content1
>                        content2
>                sub-folder2
>                content1
>                        content2
>        folder2
>                ........
>
> Regards
>
>
> George
> -----Original Message-----
> From: mreutegg@day.com [mailto:mreutegg@day.com] On Behalf Of Marcel
> Reutegger
> Sent: 15 January 2010 14:46
> To: dev
> Subject: Re: Jackrabbit Multi Threading Issue
>
> Hi,
>
> On Fri, Jan 15, 2010 at 14:02,  <ge...@bt.com> wrote:
>> Hi
>>
>> I'm using jackrabbit in a multi-threaded application.
>>
>> I have used ThreadLocal to confine the Jackrabbit Session to a single
>> thread and see no issues executing simultaneous threads except the
>> following
>> scenario:-
>>
>> - I want to create one node of type "nt:folder" and then have child
>> nodes creating under it.
>> - I attempt to get the node (of type "nt:folder") first.
>> - If I receive PathNotFoundException, then I create the node (of type
>> "nt:folder") and save the session.
>> - Some threads create extra nodes of the same name although the node
> exists?
>>
>> I've tried quite a few synchronization strategies, but no success. I
>> haven't tried node locking.
>
> what's the type of the parent node where the threads will create
> nt:folder nodes?
>
> it seems that the node type allows same name sibling child nodes.
>
> but even if you changed that you may run into another exception. after
> trying to get a node and catching the PathNotFoundException, another
> thread may have created the node meanwhile. so you probably have to
> catch another exception: ItemExistException when trying to add the
> folder node and saving it. that's kind of ugly, but will probably work.
> otherwise you should use locking.
>
> regards
>  marcel
>
>> Any help would be appreciated.
>>
>> Regards
>>
>> George Sibley
>

RE: Jackrabbit Multi Threading Issue

Posted by ge...@bt.com.
Hi Marcel

Many thanks for the reply.

Sorry should've made things clearer.

The "nt:folder" nodes are added to the root node. We then add further
"nt:folder" nodes hanging off these nodes, and then a mixture of other
nodes (e.g. "jcr:content"). E.g:-

root
	folder1
   		sub-folder1
       		content1
			content2
   		sub-folder2
       		content1
			content2
	folder2
  		........
  
Regards


George
-----Original Message-----
From: mreutegg@day.com [mailto:mreutegg@day.com] On Behalf Of Marcel
Reutegger
Sent: 15 January 2010 14:46
To: dev
Subject: Re: Jackrabbit Multi Threading Issue

Hi,

On Fri, Jan 15, 2010 at 14:02,  <ge...@bt.com> wrote:
> Hi
>
> I'm using jackrabbit in a multi-threaded application.
>
> I have used ThreadLocal to confine the Jackrabbit Session to a single 
> thread and see no issues executing simultaneous threads except the 
> following
> scenario:-
>
> - I want to create one node of type "nt:folder" and then have child 
> nodes creating under it.
> - I attempt to get the node (of type "nt:folder") first.
> - If I receive PathNotFoundException, then I create the node (of type
> "nt:folder") and save the session.
> - Some threads create extra nodes of the same name although the node
exists?
>
> I've tried quite a few synchronization strategies, but no success. I 
> haven't tried node locking.

what's the type of the parent node where the threads will create
nt:folder nodes?

it seems that the node type allows same name sibling child nodes.

but even if you changed that you may run into another exception. after
trying to get a node and catching the PathNotFoundException, another
thread may have created the node meanwhile. so you probably have to
catch another exception: ItemExistException when trying to add the
folder node and saving it. that's kind of ugly, but will probably work.
otherwise you should use locking.

regards
 marcel

> Any help would be appreciated.
>
> Regards
>
> George Sibley

Re: Jackrabbit Multi Threading Issue

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

On Fri, Jan 15, 2010 at 14:02,  <ge...@bt.com> wrote:
> Hi
>
> I'm using jackrabbit in a multi-threaded application.
>
> I have used ThreadLocal to confine the Jackrabbit Session to a single thread
> and see no issues executing simultaneous threads except the following
> scenario:-
>
> - I want to create one node of type "nt:folder" and then have child nodes
> creating under it.
> - I attempt to get the node (of type "nt:folder") first.
> - If I receive PathNotFoundException, then I create the node (of type
> "nt:folder") and save the session.
> - Some threads create extra nodes of the same name although the node exists?
>
> I've tried quite a few synchronization strategies, but no success. I haven't
> tried node locking.

what's the type of the parent node where the threads will create
nt:folder nodes?

it seems that the node type allows same name sibling child nodes.

but even if you changed that you may run into another exception. after
trying to get a node and catching the PathNotFoundException, another
thread may have created the node meanwhile. so you probably have to
catch another exception: ItemExistException when trying to add the
folder node and saving it. that's kind of ugly, but will probably
work. otherwise you should use locking.

regards
 marcel

> Any help would be appreciated.
>
> Regards
>
> George Sibley