Multithreading
You may have a simple application that requires only a single
transaction at a time. It would use a single PersistenceManager and may perform successive
transactions using the associated Transaction instance. You may have only a
single thread accessing the persistent instances and instances of the
JDO interface, but you may want multiple threads to access instances. In
this case, you need to inform the JDO implementation that multiple
threads are accessing the JDO environment.
A JDO implementation is thread safe
, which means that its behavior is predictable in the
presence of multiple application threads. When the application accesses
and modifies persistent or transactional fields of persistent instances,
the PersistenceManager performs its
operations as if the operations were serialized. It is free to serialize
internal data structures and order multithreaded operations in any way
it chooses. The only application-visible behavior is that operations
might block indefinitely (but not infinitely) while other operations
complete.
Synchronizing a PersistenceManager instance is a relatively
expensive operation. Many applications do not need multiple threads
using the same PersistenceManager
instance. If your application has multiple threads accessing a PersistenceManager or the instances it manages
(e.g., persistent or transactional instances of persistent classes,
instances of Transaction or Query, query results, etc.), you need to
notify the PersistenceManager that multiple ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access