Fast Object Database for Java - with JPA/JDO support

One transaction or two?


If I have a large number of objects to delete and then add to a PersistenceManager is it more efficient to do everything in one transaction or two? Currently my code looks like this:

PersistenceManager pm = m_pmFactory.getPersistenceManager();
try {
} finally {
    if(pm.currentTransaction().isActive()) {
    if(!pm.isClosed()) {

Should I separate the deletes and adds into separate transactions? I think I remember reading in another forum post that you recommended this, I just wanted to clarify.


Actually one transaction eliminates some overhead but may require more RAM if you have many large objects, and that may also affect performance.

I don't expect a large difference but you may want to try both options and see which is faster in your specific case.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Yeah I ran a test overnight and didn't notice any appreciable difference in performance so I think I'm just going to leave it as a single transaction. Thanks for the input!


Another question based on the same code bit above. Whenever I have objects to add/remove from the database they are submitted to an ExecutorService task. Each task then gets a Persistence Manager from the factory, performs its transaction and then closes the Persistence Manager. Under heavy load this can happen two to three hundred times per minute often times with several threads executing in parallel each with their own Persistence Manager. So over the life of the application many thousands of these are performed. Would there be much benefit to maintain a pool of Persistence Manager instances to be used across these tasks? I would include some synchronization logic to ensure that each thread had its own Persistence Manager. Is the act of creating/closing Persistence Managers heavy enough that this would provide much of a benefit?


The overhead of creating an EntityManager / PersistenceManager is low. ObjectDB already manages a pool of underlying resources (e.g. connection to the database / open database file) to keep the instantiation of these objects inexpensive.

But ObjectDB doesn't use a pool of EntityManager / PersistenceManager instances (just of some underlying resources are pooled) so if you implement such a pool you may gain some performance in some cases (e.g. if the L1 cache is important in this application). On the hand such a solution is expected to consume more memory.

Since you are asking about add/remove operations rather than read operation (in which the L1 cache is important) - performance gain, if any, is expected to be minimal. But again, to get an accurate answer you will have to try it.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply