• 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 Threads Chapter - Synchronization

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am currently preparing for SCJP. I have a doubt in Thread Chapter.

Could some one please explain the following paragraph that I have taken from SCJP 5 by Kathy Sierra and Bert.

Page Nos: 708 and 709


Page No 708 bottom:
When you synchronize a method, the object used to invoke the method is the
object whose lock must be acquired. But when you synchronize a block of code, you

Page No 709 top
specify which object's lock you want to use as the lock, so you could, for example,use some third-party object as the lock for this piece of code. That gives you the ability to have more than one lock for code synchronization within a single object.


In the above sentences when they say third-party object, do they mean a object of a different class or a different object of the same class in which the synchronized block exits.

Also please explain this line......That gives you the ability to have more than one lock for code synchronization within a single object.[/I]
..Nothing understood from this line. Please explain..

Thanks and Regards
Loga

[ November 05, 2008: Message edited by: Loganathan Karunakaran ]

[ November 05, 2008: Message edited by: Loganathan Karunakaran ]

[ November 05, 2008: Message edited by: Loganathan Karunakaran ]
[ November 05, 2008: Message edited by: Loganathan Karunakaran ]
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well third party object lock looks like this



Here a and b are third party objects of A and B respectively. and the method method1 uses synchronization lock on more than one objects...
 
Loganathan Karunakaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beautiful. Thank you so much for your explanation.

Regards
Loga
 
Ranch Hand
Posts: 61
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Good Job Man
I also confused before about above statement.
Thank you..
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was my pleasure...
 
It's feeding time! Give me the food you were going to give to 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