You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by RafalJanik <ra...@softwaremind.pl> on 2008/11/13 13:28:08 UTC

Threads in jackrabbit application

Hi
I'm testing JackRabbit and i'm wondering how it will be work when many 
users in the same time start adding the nodes and uploading the files. 
So I make few threads - each one gets reference to Session.
When task is done there is a line (Session) session.save() but if in 
another thread e.g. uploading is in progress  there  is  an Exception
(javax.jcr.nodetype.ConstraintViolationException:) - i think it is 
caused by saving action in first thread which wants to save session in 
the thread with uploading and not all mandatory fields have been written 
yet... Is it correct?
And how can I run adding or uploading nodes on two or more threads?  Is 
method join() only a reason?
What i should do to make my application with JackRabbit enable for many 
users to edit in the same time ?

Cheers

Rafael

Re: Threads in jackrabbit application

Posted by Alexander Klimetschek <ak...@day.com>.
Hi Rafael,

Sessions in JCR are not thread-safe, so each user/request should have
its own session (Sessions are designed to be retrieved and released
quickly, unlike a jdbc connection). If all your threads use the same
session, this might be the reason for the (somewhat unexpected)
ConstraintViolationException.

To avoid conflicts, you can solve that by using a good content model
or for example using open-scoped locking. You might also design your
application to handle conflicts, ie. keep the content that could not
be saved and offer a conflict resolution to the user (eg. "was already
modified, here is the difference / do you want to overwrite / etc.").

Regards,
Alex

On Thu, Nov 13, 2008 at 1:28 PM, RafalJanik <ra...@softwaremind.pl> wrote:
> Hi
> I'm testing JackRabbit and i'm wondering how it will be work when many users
> in the same time start adding the nodes and uploading the files. So I make
> few threads - each one gets reference to Session.
> When task is done there is a line (Session) session.save() but if in another
> thread e.g. uploading is in progress  there  is  an Exception
> (javax.jcr.nodetype.ConstraintViolationException:) - i think it is caused by
> saving action in first thread which wants to save session in the thread with
> uploading and not all mandatory fields have been written yet... Is it
> correct?
> And how can I run adding or uploading nodes on two or more threads?  Is
> method join() only a reason?
> What i should do to make my application with JackRabbit enable for many
> users to edit in the same time ?
>
> Cheers
>
> Rafael
>



-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Threads in jackrabbit application

Posted by RafalJanik <ra...@softwaremind.pl>.
Thank You i will try it:)

Jukka Zitting pisze:
> Hi,
>
> On Thu, Nov 13, 2008 at 2:32 PM, RafalJanik <ra...@softwaremind.pl> wrote:
>   
>> When i try to make in each thread its own session i get
>> javax.jcr.RepositoryException that the repository home  "appears to be in
>> use since the file named .lock is locked by another process.
>>     
>
> That message is caused by you creating more than one Repository
> instance. You can only have one Repository instance per a repository
> you are accessing, but you can use Repository.login() to create any
> number of sessions for concurrently accessing that repository.
>
> BR,
>
> Jukka Zitting
>
>   


Re: Threads in jackrabbit application

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Nov 13, 2008 at 2:32 PM, RafalJanik <ra...@softwaremind.pl> wrote:
> When i try to make in each thread its own session i get
> javax.jcr.RepositoryException that the repository home  "appears to be in
> use since the file named .lock is locked by another process.

That message is caused by you creating more than one Repository
instance. You can only have one Repository instance per a repository
you are accessing, but you can use Repository.login() to create any
number of sessions for concurrently accessing that repository.

BR,

Jukka Zitting

Re: Threads in jackrabbit application

Posted by RafalJanik <ra...@softwaremind.pl>.
When i try to make in each thread its own session i get 
javax.jcr.RepositoryException that the repository home  "appears to be 
in use since the file named .lock is locked by another process.
So is there any other way to start session in each thread or a have to 
use notify()?

Rafael


> Hi,
>
> On Thu, Nov 13, 2008 at 1:28 PM, RafalJanik <ra...@softwaremind.pl> wrote:
>   
>> I'm testing JackRabbit and i'm wondering how it will be work when many users
>> in the same time start adding the nodes and uploading the files. So I make
>> few threads - each one gets reference to Session.
>>     
>
> You'll want to make sure that each thread has its own session. JCR
> sessions are not thread-safe!
>
> BR,
>
> Jukka Zitting
>
>   


Re: Threads in jackrabbit application

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Thu, Nov 13, 2008 at 1:28 PM, RafalJanik <ra...@softwaremind.pl> wrote:
> I'm testing JackRabbit and i'm wondering how it will be work when many users
> in the same time start adding the nodes and uploading the files. So I make
> few threads - each one gets reference to Session.

You'll want to make sure that each thread has its own session. JCR
sessions are not thread-safe!

BR,

Jukka Zitting