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 luke cassady-dorion <lu...@netraker.com> on 2003/05/01 18:55:50 UTC

PersistenceBroker best practices

I'm trying to figure out the best way to make use of the
PersistenceBroker class. I've been digging at the source and am not sure
i still fully understand it. I realize that there exists a pool of these
objects and if that pool is used up, that an exception will be thrown.
So here are my questions:

- When i am done with a PersistenceBroker object, should i return it to
the pool? If so, how is this done?

- should i just use one PersistenceBroker object throughout my whole
application? (some of the tutorial apps do this), or will this mean that
all transactions are performed in series instead of in parallel where
possible. Will using one PersistenceBroker object cause problems in a
multi-threaded environment?

- how are db connections pooled? Is the model basically one connection
per PersistenceBroker object?

Thnx in advance ... if there is documentation on this, can someone
forward me the link? I can't seem to find it.

-lcd


Re: PersistenceBroker best practices

Posted by Thomas Mahler <th...@web.de>.
Hi Luke,

luke cassady-dorion wrote:
> I'm trying to figure out the best way to make use of the
> PersistenceBroker class. I've been digging at the source and am not sure
> i still fully understand it. I realize that there exists a pool of these
> objects and if that pool is used up, that an exception will be thrown.
> So here are my questions:
> 
> - When i am done with a PersistenceBroker object, should i return it to
> the pool? If so, how is this done?

Yes! broker.close() will close all resources (e.g. JDBC connections) 
used by that broker and return the instance to the pool.

be careful not to use closed broker instances.

> 
> - should i just use one PersistenceBroker object throughout my whole
> application? (some of the tutorial apps do this), or will this mean that
> all transactions are performed in series instead of in parallel where
> possible. 

The tutorials are very simple single threaded apps. SO we just work with 
a single broker.

> Will using one PersistenceBroker object cause problems in a
> multi-threaded environment?

One broker can only process one transaction at one point in time. So in 
a multithreaded environment a single broker will become a bottleneck...

The usually best thing is to use brokers as short as possible and to 
return them asap back to the pool. This will help to scale your application.
If you have a fixed number of threads it's also ok to use one dedicated 
broker per thread.

> - how are db connections pooled? Is the model basically one connection
> per PersistenceBroker object?
The connection pooling behaviour depends on the settings in 
OJB.properties. This file also contains explanations for all existing modes.

cheers,
Thomas

> 
> Thnx in advance ... if there is documentation on this, can someone
> forward me the link? I can't seem to find it.
> 
> -lcd
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


Re: PersistenceBroker best practices

Posted by Rajeev Kaul <Ra...@customercaresolutions.com>.
Look at the test cases accompanying OJB.  You will find lots of examples on
how to use the PB.

----- Original Message -----
From: "luke cassady-dorion" <lu...@netraker.com>
To: "'OJB Users List'" <oj...@db.apache.org>
Sent: Thursday, May 01, 2003 9:55 AM
Subject: PersistenceBroker best practices


> I'm trying to figure out the best way to make use of the
> PersistenceBroker class. I've been digging at the source and am not sure
> i still fully understand it. I realize that there exists a pool of these
> objects and if that pool is used up, that an exception will be thrown.
> So here are my questions:
>
> - When i am done with a PersistenceBroker object, should i return it to
> the pool? If so, how is this done?
>
> - should i just use one PersistenceBroker object throughout my whole
> application? (some of the tutorial apps do this), or will this mean that
> all transactions are performed in series instead of in parallel where
> possible. Will using one PersistenceBroker object cause problems in a
> multi-threaded environment?
>
> - how are db connections pooled? Is the model basically one connection
> per PersistenceBroker object?
>
> Thnx in advance ... if there is documentation on this, can someone
> forward me the link? I can't seem to find it.
>
> -lcd
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org