File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in synchronization

 
kapil kumar
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
kapil kumar
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks john......
next time i will post the code too
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic