Questions tagged [pessimistic-locking]

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete.

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete. The database record is locked immediately when the lock is requested and it is then guaranteed that the database record will be updated. Unlike optimistic locking, great care must be taken in the application design to avoid deadlocks.

178 questions
1
vote
2 answers

Hibernate Pessimistic Locking mode

I am trying to understand pessimistic locking mechanism in Hibernate (Over MySQL DB). I tried running the following example: public static void main(String[] args) { SessionFactory sessionFactory = new…
Nick Div
  • 5,338
  • 12
  • 65
  • 127
1
vote
1 answer

grails/hibernate: add pessimistic locking on using creteria

I tried to add a pessimistic locking in my creteria as it shown in the doc http://grails.org/doc/latest/guide/GORM.html#locking but I had an exception: "ERROR util.JDBCExceptionReporter - Feature not supported: "FOR UPDATE && JOIN"; SQL…
Jils
  • 783
  • 5
  • 12
  • 32
1
vote
0 answers

jOOQ SELECT FOR UPDATE lock never released

I'm using jOOQ to do a SELECT FOR UPDATE on a row to synchronize a subsequent MERGE operation. However when the MERGE is completed, the lock held by the FOR UPDATE is never released. My DataSourceConnectionProvider has been fed a…
George Burdell
  • 1,349
  • 2
  • 12
  • 20
1
vote
1 answer

Pessimistic vs. optimistic concurrency control

I have a question about pessimistic versus optimistic locking. Everybody says that "Optimistic locking is used when you don't expect many collisions.", for example: which concurrency control is more efficient pessimistic or optimistic concurrency…
user1255553
  • 960
  • 2
  • 15
  • 27
1
vote
1 answer

Infinispan cache does not throw exception in pessimistic mode

I am running simple test case based on one of the Infinispan unit tests. In my test I expect to receive CacheException when replication timeouts in my cluster. I use pessimistic transaction locking and exception is not thrown in this case for some…
hoaz
  • 9,883
  • 4
  • 42
  • 53
1
vote
1 answer

Rails 3: How to simply test pessimistic locking on console

I'm currently doing a pessimistic loking with rails 3 + postgresql. But there seems to be no way to confirm that the lock is working unless I go through the hassle of making a concurrent test. Is there no way to test this via…
1
vote
0 answers

JSF/JPA/EJB Best practice for locking an entity from the "Edit" page

We have a basic JSF/EJB/JPA web application in which the EJB business beans work with JPA / entity manager and manage all transactions. That is: Page.xhtml => PageBean.java => BusinessBean.java => Entity.java Where Page.xhtml displays values for…
1
vote
1 answer

Save object without releasing lock?

Let's say I have a domain object which was selected with "lock:true", or simply locked afterwards. Is there a way to save() it's state to the database without releasing the lock? (As I understaind, the default behavior is that save() releases the…
Cray
  • 2,396
  • 19
  • 29
1
vote
1 answer

Pessimistic locking worst case

We are using Java EE. And are making an apllication where in the worst case, aloot of message queue messages willl come form the same User. Therefore we are looking on Pessimistic, SELECT FOR UPDATE style locking. Which in theory and fisrt tests…
user21549
  • 13
  • 2
1
vote
0 answers

Distributed Multi-resource Pessimistic Locking Algorithm

I'm implementing pessimistic locking for a distributed key-value store. I have a rock-solid atomic compare-exchange (and increment and decrement) operation for implementing the locks. There's also data structures for sets, sorted sets, lists, and…
Brent
  • 4,153
  • 4
  • 30
  • 63
0
votes
1 answer

LockMode in EJB3 Persistence NamedQuery

How do we specify LockMode in EJB3 Persistence NamedQuery? I want to add Pessimistic LockMode to my existing select so that I can update if necessary but surprisingly Query object doesnot have setLockMode(xxx) method ( My understanding was if JPA, …
phewataal
  • 1,107
  • 4
  • 12
  • 23
0
votes
0 answers

How to optimize query if it uses Pessimistic Write Lock

I have a method that can have 1000 requests per second. I need to pause request until one finishes the method. I used Lock Pessimistic Write but It slows response(time about 10 seconds ) What can do the same task with Pessimistic Write but more…
0
votes
0 answers

When will the PESSIMISTIC READ lock be released if we use it within nested transaction?

We use a Spring Boot 2.5 with Java 17 and Postgres DB. We have a method example() annotated with @Transactional(propagation = Propagation.NESTED). Within example() method we use repository method "getData()" which has…
0
votes
0 answers

saveAll() causing Lock wait timeout exceeded org.hibernate.PessimisticLockException: could not execute statement while doing saveAll()

I am using a JPA repository to save the entity to database Table is something like this. CREATE TABLE IF NOT EXISTS Data_Catalog( F_Id bigint auto_increment primary key, Name varchar(500), Age int ); java…
0
votes
0 answers

Mongodb concurrent updates of counter do not maintain consistency with findAndModify

We have counter stored in mongodb and multiple threads are trying to read and increment the counter. Can one thread override the value of other with findAndModify(). For example counter value is 1 if 6 threads increasing the conuter concurrently by…