• 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

Multithreading

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

what is the purpose of locking an object of class Object like this .
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no way this code will compile.
Beyond that, using an explicit lock object instead of the intrinsic lock allows different methods to use different locks, thereby avoiding contention and exposing the lock externally. In the case of MySemaphore there are only two methods that both lock on the same object, but the approach is still valid. If these methods used the intrinsic lock, then code external to MySemaphore could use a MySemaphore instance as an explicit lock object. That external code and the methods in MySemaphore would then be using the same lock - the intrinsic lock of the MySemaphore instance. The explicit lock object avoids this.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mandeepsangwan,
Please read what is Semaphore and how it is working :webpage

Regarding your code , I should say basics are not strong , you have declared static methods and doing object level locking !!! How could you mix class level and object level lock .Please read basics of threads .

Thanks ,
Satya
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic