7.6. Closing the PersistenceManagerFactory

public boolean isClosed ();
public void close ();

PersistenceManagerFactories are heavyweight objects. Each factory might maintain a metadata cache, object state cache, PersistenceManager pool, connection pool, and more. If your application no longer needs a PersistenceManagerFactory, you should close it to free these resources. When a PersistenceManagerFactory closes, all PersistenceManagers from that factory, and by extension all persistent objects managed by those PersistenceManagers, become invalid. Attempting to close a PersistenceManagerFactory while one or more of its PersistenceManagers has an active transaction results in a JDOUserException.

Closing a PersistenceManagerFactory should not be taken lightly. It is much better to keep a factory open for a long period of time than to repeatedly create and close new factories. Thus, most applications will never close the factory, or only close it when the application is exiting. Only applications that require multiple factories with different configurations have an obvious reason to create and close multiple PersistenceManagerFactory instances. In fact, because closing a PersistenceManagerFactory has such drastic consequences, it requires that the current security context have the closePersistenceManagerFactory JDOPermission. Once a factory is closed, all methods except isClosed throw a JDOUserException.


Skip navigation bar   Back to Top