Metal Wing
Metal Wing

Reputation: 545

NetBeans Platform: Entity record lock - different applications

I have an inquiry regarding record lock in NetBeans Platform.

So I have a database with DBF tables. I have a NetBeans Platform application which I run and it accesses those tables. It locks a record in one of them.

I have another instance of NetBeans Platform Application which I run. I am trying to make it so if there is multiple instances of NetBeans Platform Applications are open, only 1 can access the locked record in database. I am failing at achieving that.

Correct me if I am wrong, but entitymanager.lock is specific to the EntityManage instance within the application. So if I Application1.entityManager.lock locks a record, then Application2.entityManager wont know about the lock?

So I guess another question is: is it possible to have 2 instances of the same NetBeans Application share the same EntityManager?

Thank You

Upvotes: 0

Views: 152

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42114

First of all, instance of EntityManager is not guaranteed to be thread safe. This means that specification does not expect implementations to be thread safe and discourages sharing instances of entity manager - still it is of course aloud to build thread safe implementation. Consequence is that you do not want to share entity manager.

Locking is performed via entity manager, but rows are locked in database. In specification this is spelled with following words:

When an entity instance is locked using pessimistic locking, the persistence provider must lock the database row(s) that correspond to the non-collection-valued persistent state of that instance.

Upvotes: 1

Related Questions