Govind Mantri
Govind Mantri

Reputation: 803

Neo4j transaction locking

I'm using Embedded JavaAPI for my realtime application. While one transaction is locked the database my other ajax call throws error that DB instance has been locked by other process. Most of the time my calls are read-only. So my question is: Is there any method exists in Neo4J JavaAPI so that I can lock my transaction as read-only so that other request can get data from DB.

dbFactory = new GraphDatabaseFactory();
db= dbFactory.newEmbeddedDatabase(DB_PATH);
tx = db.beginTx();

so at this db.beginTx() can I tell Neo4j that it is a read-only mode or something like that.

Thanks,

Upvotes: 4

Views: 5406

Answers (1)

FylmTM
FylmTM

Reputation: 2007

Unfortunately there is no such method. But, in fact - it is not needed.

Neo4j locking behaviour

Read locks: they are "shared". If one transaction reads data from node, then other transaction can do this also.

Write locks: they are "exclusive". When write lock is taken, all transactions will wait until this lock will be relased and only then proceed further. If another transaction has Read lock on node, then write lock will wait until this node will be "free".

In normal case - you should not receive any errors.

There is possibility to get DeadlockException (more info), but it's rare case. If you don't use your own synchronization methods, then you will not see such exceptions.

EDIT:

You should ensure that you have only one instance of GraphDatabaseService in your application. DB instance is completely threadsafe.

Upvotes: 5

Related Questions