• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about putting this situation into code?
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thread B can access the non-synchronized method, since the object's lock is not needed.
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic