This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread will aquire lock of which object ... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "thread will aquire lock of which object ..." Watch "thread will aquire lock of which object ..." New topic
Author

thread will aquire lock of which object ...

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3829
synchronized block :

synchronized(ob) {

}

In this case ob has lock & the thread executing this block will aquire that lock .
--------------------------------------------------
synchronized method :

synchronized void m() {

}

main thread is executing this method , so it will aquire lock of which object ???

thanks a lot .
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16693
    
  19

Originally posted by rathi ji:
synchronized method :

synchronized void m() {

}

main thread is executing this method , so it will aquire lock of which object ???

thanks a lot .


In this case, (the method is not static), the object that is used for the lock is the "this" object.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: thread will aquire lock of which object ...
 
Similar Threads
Thread Doubt
synchronized block
Threads and Synchronization
Transistion from blocked to runnable
Syncronizing variables or classes - Exercise 9-2