It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Shiaber Shaam
Ranch Hand

Joined: Jun 16, 2006
Posts: 252
Consider i have 2 methods in a class, 1 is synchronized and other is not. If Thread A acquires lock on an instance and executing the synchronized method, can Thread B execute the non synchronized method on the same instance?


$Hi/\bEr
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

How about putting this situation into code?


Mohamed Sanaulla | My Blog
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Yes, thread B can access the non-synchronized method, since the object's lock is not needed.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

Yes the non-synchronized method can be invoked. Infact another synchronized method which requires locking some other instance than the first method is also invokable at the same time by a different thread.


Java Experience
 
 
subject: Threads
 
Similar Threads
Synchronised Methods
static synchronized
keyword synchronized
Thread locks
lock for instance method and class static method