You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Denis Avdic <de...@betterway.net> on 2003/06/10 21:40:22 UTC
Multiple threads using one broker
Hi,
I am using OJB with Struts and I have a number of actions that use
persistence broker calls to retrieve and store data.
Now, if I have a number of users using the application, all users share
the same broker. Thus I get collisions where one user would begin a
transaction then another would begin a transaction (and get an
exception) and then first user would commit transaction, and when the
second user would try to commit transaction I get an error.
What can I do to fix this, is there anything in the configuration I can
do, or does anyone have a trick for this?
my broker is a regular broker I get by calling
PersistenceBrokerFactory.defaultPersistenceBroker();
TIA,
Denis
Re: Multiple threads using one broker
Posted by "David C. Hicks" <dh...@i-hicks.org>.
It doesn't sound reasonable that different users would collide with one
another in a transaction environment unless they are always working on
the same data. If they *are* working on the same data, then you should
expect collisions and have your application manage that for the user in
a clean way. If your users are working on different pieces of data and
you're still getting collisions, then my guess is that your data model
is flawed in some way as to allow this to happen.
Dave
Denis Avdic wrote:
> Now, if I have a number of users using the application, all users
> share the same broker. Thus I get collisions where one user would
> begin a transaction then another would begin a transaction (and get an
> exception) and then first user would commit transaction, and when the
> second user would try to commit transaction I get an error.
>
Re: Multiple threads using one broker
Posted by Thomas Mahler <th...@web.de>.
Hi,
Yajun Liu wrote:
> Does closing broker close database connection?
connection.close() is called. But we are using connection-pooling!
Thus close() does not close the connection but returns it to the pool!
So it's not expensive, but increases scalability.
cheers,
Thomas
> If yes, then it is too
> expensive.
>
> --Yajun
>
> ----- Original Message -----
> From: "Armin Waibel" <ar...@code-au-lait.de>
> To: "OJB Users List" <oj...@db.apache.org>
> Sent: Tuesday, June 10, 2003 4:20 PM
> Subject: Re: Multiple threads using one broker
>
>
>
>>Hi Denis,
>>
>>----- Original Message -----
>>From: "Denis Avdic" <de...@betterway.net>
>>To: "OJB Users List" <oj...@db.apache.org>
>>Sent: Tuesday, June 10, 2003 9:40 PM
>>Subject: Multiple threads using one broker
>>
>>
>>
>>>Hi,
>>>
>>>I am using OJB with Struts and I have a number of actions that use
>>>persistence broker calls to retrieve and store data.
>>>
>>>Now, if I have a number of users using the application, all users
>>
>>share
>>
>>>the same broker.
>>
>>PersistenceBroker instance itself is not threadsafe. For this reason
>>OJB use a PB-pool to allow a per thread handling of PB instances.
>>Mean each user should get his own PB instance. Get the broker,
>>do the work, close the broker. Or you have
>>to synchronize user action.
>>
>>regards,
>>Armin
>>
>>
>>>Thus I get collisions where one user would begin a
>>>transaction then another would begin a transaction (and get an
>>>exception) and then first user would commit transaction, and when the
>>>second user would try to commit transaction I get an error.
>>>
>>>What can I do to fix this, is there anything in the configuration I
>>
>>can
>>
>>>do, or does anyone have a trick for this?
>>>
>>>my broker is a regular broker I get by calling
>>>PersistenceBrokerFactory.defaultPersistenceBroker();
>>>
>>>TIA,
>>>
>>>Denis
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
Re: Multiple threads using one broker
Posted by Yajun Liu <yl...@attbi.com>.
Does closing broker close database connection? If yes, then it is too
expensive.
--Yajun
----- Original Message -----
From: "Armin Waibel" <ar...@code-au-lait.de>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Tuesday, June 10, 2003 4:20 PM
Subject: Re: Multiple threads using one broker
> Hi Denis,
>
> ----- Original Message -----
> From: "Denis Avdic" <de...@betterway.net>
> To: "OJB Users List" <oj...@db.apache.org>
> Sent: Tuesday, June 10, 2003 9:40 PM
> Subject: Multiple threads using one broker
>
>
> > Hi,
> >
> > I am using OJB with Struts and I have a number of actions that use
> > persistence broker calls to retrieve and store data.
> >
> > Now, if I have a number of users using the application, all users
> share
> > the same broker.
>
> PersistenceBroker instance itself is not threadsafe. For this reason
> OJB use a PB-pool to allow a per thread handling of PB instances.
> Mean each user should get his own PB instance. Get the broker,
> do the work, close the broker. Or you have
> to synchronize user action.
>
> regards,
> Armin
>
> > Thus I get collisions where one user would begin a
> > transaction then another would begin a transaction (and get an
> > exception) and then first user would commit transaction, and when the
> > second user would try to commit transaction I get an error.
> >
> > What can I do to fix this, is there anything in the configuration I
> can
> > do, or does anyone have a trick for this?
> >
> > my broker is a regular broker I get by calling
> > PersistenceBrokerFactory.defaultPersistenceBroker();
> >
> > TIA,
> >
> > Denis
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
Re: Multiple threads using one broker
Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Denis,
----- Original Message -----
From: "Denis Avdic" <de...@betterway.net>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Tuesday, June 10, 2003 9:40 PM
Subject: Multiple threads using one broker
> Hi,
>
> I am using OJB with Struts and I have a number of actions that use
> persistence broker calls to retrieve and store data.
>
> Now, if I have a number of users using the application, all users
share
> the same broker.
PersistenceBroker instance itself is not threadsafe. For this reason
OJB use a PB-pool to allow a per thread handling of PB instances.
Mean each user should get his own PB instance. Get the broker,
do the work, close the broker. Or you have
to synchronize user action.
regards,
Armin
> Thus I get collisions where one user would begin a
> transaction then another would begin a transaction (and get an
> exception) and then first user would commit transaction, and when the
> second user would try to commit transaction I get an error.
>
> What can I do to fix this, is there anything in the configuration I
can
> do, or does anyone have a trick for this?
>
> my broker is a regular broker I get by calling
> PersistenceBrokerFactory.defaultPersistenceBroker();
>
> TIA,
>
> Denis
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
Re: Multiple threads using one broker
Posted by Thomas Mahler <th...@web.de>.
Hi Denis,
A broker can only handle one tx at a time.
To avoid conflicts with multiple users opening broker transactions in
parallel you simply have to use one broker per user request.
please study the literature and tutorials on ojb + struts best practices:
http://db.apache.org/ojb/links.html
cheers,
Thomas
Denis Avdic wrote:
> Hi,
>
> I am using OJB with Struts and I have a number of actions that use
> persistence broker calls to retrieve and store data.
>
> Now, if I have a number of users using the application, all users share
> the same broker. Thus I get collisions where one user would begin a
> transaction then another would begin a transaction (and get an
> exception) and then first user would commit transaction, and when the
> second user would try to commit transaction I get an error.
>
> What can I do to fix this, is there anything in the configuration I can
> do, or does anyone have a trick for this?
>
> my broker is a regular broker I get by calling
> PersistenceBrokerFactory.defaultPersistenceBroker();
>
> TIA,
>
> Denis
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>