This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronization question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Synchronization question" Watch "Synchronization question" New topic
Author

Synchronization question

David Pantale
Ranch Hand

Joined: Mar 16, 2010
Posts: 32
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

Joined: Dec 28, 2007
Posts: 2258
    
    3

David Pantale wrote:Okay, answer found and apparently not a problem


Alright! Good news!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronization question
 
Similar Threads
B&S & Denny's: Design decisions (locking stuff really)
Take this Testing Tool for Data Class
Create/Update Method Synchronization
question the lock() and unlock()
Possibility of Locking a Record, that has just been deleted.