Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization question

 
David Pantale
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing my final testing and noticed something disturbing. In my lockRecord method ( which I have written as public synchronized long lockRecord(long recNo)), I have thread 1 entering the code (according to my println statement) and half way through the code, before an actual lock is made on the record number, thread 2 begins executing lockRecord (according to println statement). My understanding was that once a thread entered synchronized code it could not be swapped out and another thread start running in the same code. Am I mistaken? Any suggestions as to how this happens?

(And, yes, my data object is a singleton)

Thanks
Dave

Follow up: Okay, answer found and apparently not a problem - I just got upset and overreacted. My printlin comments were not complete enough, the synchronized code had actually ended when errors were thrown but my println statements did not reflect that. By adding a few extra println statements the mystery was solved.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Pantale wrote:Okay, answer found and apparently not a problem


Alright! Good news!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic