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
3
votes
1 answer

Is it possible to "lock" and "unlock" a pessimistic lock in two different methods in Spring Boot?

I am currently having the need of using pessimistic lock in my vending machine project. When more than 1 person is choosing their products, I would like to use the pessimistic lock to prevent both people from selecting the same product. My project…
Power_tile
  • 578
  • 1
  • 6
  • 18
3
votes
2 answers

How can I have rails select for update on multiple rows?

I can't figure out how to tell rails to SELECT ... FOR UPDATE on multiple rows. Poking around in console, Foo.where(bar: "baz").lock does produce the right SQL. But when I try to do it in a transaction, that ruby code doesn't actually generate the…
John Bachir
  • 22,495
  • 29
  • 154
  • 227
3
votes
1 answer

Optimistic concurrency control and write skew

I feel kind of stupid asking this question, but to clear things out, sometimes stupid questions must be asked :) So, we can define a write skew as Martin Kleppmann did in his talk: Write skew pattern: 1. read something 2. make a decision 3.…
3
votes
4 answers

How do I block this race condition in an inventory allocation scenario?

I'm wrestling with the classic problem of inventory allocation and concurrency and I wondered if anyone could give me a steer on best practice in this situation. My situation is that we have an order prepared with several "slots" which will be…
3
votes
2 answers

JPA synchronizing entity accessors

Here's the setup: the entity class has the collection of other entities that is loaded lazily. The trick is, I need to perform some data-related work (for example, I want to calculate certain checksum with the elements of collection). The trick…
Juriy
  • 5,009
  • 8
  • 37
  • 52
3
votes
0 answers

hibernate locking mode to lock multiple rows at once

How can I lock multiple rows at once in hibernate locking. Currently I am firing a select query to fetch multiple rows with an OR clause and locking the query with set lock mode for pessimistic lock mode. However in the hibernate logs I am seeing…
3
votes
1 answer

Hibernate LockMode release and fail-fast if the lock cannot be acquired

I have two questions regarding the Pessimistic LockModes that are available in Hibernate 3.3.2.ga : If I lock a set of rows using lockmode UPGRADE, do the locks gets released when you move out of the transaction scope? If yes, can we lock-unlock…
3
votes
1 answer

Hibernate: lockMode for criteria is not working

I need to specify lock mode for hibernate. What I am doing: session().createCriteria(clazz, "c") .add(Restrictions.eq("c.a", false)) .add(Subqueries.propertyEq("c.b", subquery)) .setLockMode("pos", LockMode.PESSIMISTIC_READ); But when I see…
Igor Konoplyanko
  • 9,176
  • 6
  • 57
  • 100
3
votes
1 answer

Hybrid optmistic / pessimistic locks

The application Hi, We have an application (J2EE/Hibernate/JPA) with several users making actions on a common entity. To simplify, let's say this application is like Google docs : A shared document on which many users can update at the same time. We…
3
votes
1 answer

pessimistic locking: Lock database entity grails

I followed the grails documenation it says that to do pessimistic locking I can do like this: def plan = Plan.findWhere(user:user, [lock: true]) so this locks the plan instance until save is finished on it.Now in my case I want to lock multiple…
vishesh
  • 2,007
  • 6
  • 32
  • 67
3
votes
1 answer

Adding an item to Microsoft.ApplicationServer.Caching.DataCache with pessimistic locking?

I'm working on a caching layer on a web server on the serverside, using Azure Shared Caching, to reduce the amount of requests to the database and thus make stuff run faster (hopefully). What I'm getting stuck on is how the make the whole endevour…
3
votes
1 answer

Whats the best approach to handle pessimistic concurrency in Azure Cache?

I am new to azure caching and facing one problem. I will brief about the scenario first. We are using SQL Azure as DB for our application. To avoid the latency issues and Throttling issues we are using Azure Caching (co-located caching on web…
2
votes
0 answers

Spring Data @lock(lockmodetype.pessimistic_write) not working as well

I am using Spring Boot and Oracle Database with Spring Data ORM, when I use bellow code @Lock(LockModeType.PESSIMISTIC_WRITE) @Query("SELECT c FROM Customer c WHERE c.orgId = ?1") public List fetchCustomersByOrgId(Long orgId); I expect…
2
votes
2 answers

Handling concurrency condition in entity framework core to prevent race condition

I am trying to run a test case and trying to pass two schedules inside like below: var itemToAdd = new ScheduleInputItemDto { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), ProdType = "Prod1" }; var…
2
votes
1 answer

Spring JPA Transactional commit during process with Pessimistic lock

I need to perform the batch operation with a Pessimistic lock so that no other can read or write this row during this operation. But I want to increment the page number after every batch so that if the transaction failed or instance died, I will…
1 2
3
11 12