Hi,
I'm trying to apply pessimistic locking on a field in one of my DB tables, using PostgreSQL, Spring and Hibernate.
I tested my locking with two threads trying to read the field (select .. for update), sleep, update it, release the lock .. BUT it doesn't work ..
The weird thing (to me) is that it works when i use two different processes to update the field.
The stages are like this :
( thread1 = T1, thread2 = T2, process1 = P1, process2 = P2 )
with threads :
T1 read
T2 read
T1 sleep
...
T1 update
T1 close the connexion
T2 NEVER wakes up
with processes :
P1 read
P2 read
P1 sleep
...
P1 update
P1 closes the connexion
P2 wakes up
P2 sleep
...
P2 updates
P2 closes the connexion
So it works with two processes but not with two threads in the same process...
Does anyone have an idea or need more information (code snippets, .. ) and could help ?
Thanks in advance,
Oliver


Reply With Quote