Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Threads, synchronized blocks, and 3rd Parties

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm currently focusing on threads, synchronization, and all that... In the Sierra/Bates book (p. 523), there is the following paragraph:

"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 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."

So, I have two questions:
1. Can anyone who thinks they know how to interpret this passage re: third-party objects and locks shed a little more light on the topic?

2. Is the below code an example of what's being talked about above? For example, is a below a "third-party"?

Thanks, Pete.
[ April 03, 2005: Message edited by: Pete Knecht ]
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Pete,


1. Can anyone who thinks they know how to interpret this passage re: third-party objects and locks shed a little more light on the topic?


Third party objects here mean, not belonging to the current object.
Take up this example what i have given,

In this example, the thread blocks on the StringBuffer object which is obviously a thridr party for the thread.


2) Yeah ur example is also fine.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic