aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in synchronization" Watch "doubt in synchronization" New topic
Author

doubt in synchronization

kapil kumar
Greenhorn

Joined: May 22, 2008
Posts: 25
suppose i am calling a synchronized method say method1() using a thread say thread1 on an object say obj1
This synchronised method is calling another non synchronised method say method2() on the same object obj1
my question is will another thread say thread2 will be able to call method2() on the same instance obj1 if thread1 is holding a lock on obj1


If you can't be the Sun ..<br /> Be a star ..............
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Originally posted by kapil kumar:
suppose i am calling a synchronized method say method1() using a thread say thread1 on an object say obj1
This synchronised method is calling another non synchronised method say method2() on the same object obj1
my question is will another thread say thread2 will be able to call method2() on the same instance obj1 if thread1 is holding a lock on obj1


Yes. Since this method is not synchronized the object lock is not required to call this methods. You have method1() and to execute it object1's lock was obtained. To execute method2() the object1 lock is not required since it is not synchronized. If it were then thread 2 will have to wait till thread1 finishes with method1().

If you illustrate the question with a class next time you will perhaps attract more replies. Good luck with your exam


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
kapil kumar
Greenhorn

Joined: May 22, 2008
Posts: 25
thanks john......
next time i will post the code too
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in synchronization