• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in synchronization

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks john......
next time i will post the code too
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic