Hi Bobby,
Bobby Lawrence wrote:
Armin -
There really isn't a "problem". It was more of a question concerning performance.
Currently, I am using multiple PB instances to access different databases.
ok, this is needed, because each broker instance was associated with a database when it's initialized.
I was only asking if it would be more efficient if instead of accessing multiple brokers in one thread, if I could distribute the work between multiple threads and have the application run faster or use less memory.
The PB isn't threadsafe, so if you take care concurrency it will be possible (using your trick with PBThreadMapping).
- Faster?
Not much, because the PB instances are pooled, so lookup and close doesn't take (much) time.
- less memory?
Shouldn't' be problematic, because the metadata information (class-descriptor declaration) is shared, thus an PB instance doesn't allocate much memory (I suppose so ;-)).
You stated "Use the PB to do the work and immediately close the PB after use."
Why would you need to "... immediately close the PB after use."?
The PB.close() call will definitely release the used connection (PB.commit...,abort... will too), return the PB instance back to pool and do some internal clean-up. This help to avoid an exhausted PB-pool in multithreaded environments. In a single thread (or with less fixed threads) application it's not needed to close the PB immediately after use.
My application might have to go back to that PB multiple times before it stops running...
Also - why do you "strongly advise against using internal non-api classes"? I don't know what you mean. You mean don't extend any OJB classes?
No, no this wouldn't be good public relations ;-)
I mean this class is only for internal use by OJB, as mentioned in the javadoc's
http://db.apache.org/ojb/api/org/apache/ojb/broker/core/PersistenceBrokerThreadMapping.html
and could be changed, removed, renamed in next version without announcement.
regards, Armin
--bobby
Armin Waibel wrote:
Hi Robert,
[EMAIL PROTECTED] wrote:
My OJB application uses multiple PersistenceBrokers to access different databases. The only way I could do it was by calling PersistenceBrokerThreadMapping.setCurrentPersistenceBroker(<broker>); because the app was running in its one thread.
Sorry, think I don't understand the problem. You can lookup several PB instances each access a different DB.
http://db.apache.org/ojb/docu/faq.html#lookupPB http://db.apache.org/ojb/docu/faq.html#multipleDB
I was just wondering if you spawned multiple threads, each with its own broker, and each broker accessing different databases .... could you get your app to get data from the brokers in each thread?
yep, no problem (or if you don't think so, please describe the problem more detailed - code snip). Lookup an PB instance in each thread using a PBKey to specify the DB (using jcdAlias name defined in jdbc-connection-descriptor). Use the PB to do the work and immediately close the PB after use.
And would it be
faster or more efficient than what I'm doing now? (it works fine, but I'm
worried about dealing with memory and run time issues)
Not sure what you are doing (sharing one PB instance in your app?), but I strongly advise against using internal non-api classes.
regards, Armin
--Bobby
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
