This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Developer Career Masterplan: Build your path to senior level and beyond with practical insights from industry experts and have Heather VanCura and Bruno Souza on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

About Synchronization concept of static and non static method using Class level lock

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please go through from following code and help me out in Synchronization concept.
Q1. from Class level lock can we able to call non static synchronized method simultaneously ?
Q2. If more than 1 threads are running then they can operate on same static synchronized method simultaneously ?
Q3. From class level lock can more than 1 threads able to execute non static synchronized method ?
Please give me reply......


Thanks & Regards
-Ritesh R Somani
 
author
Posts: 23939
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please QuoteYourSources.

 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, synchronizing a non-static method means synchronize(this) where this is the instance that calls the method. That means this instance is locked by one thread at a time.
Synchronizing a static method means synchronizied (ThreadDemo8.class), or any other class object. That means this class object is locked by one thread at a time.
One thread can lock the class object while another thread can lock the instance.

So, if two threads access the same object such as ThreadDemo8, the non-static syn method and static syn method can be accessed concurrently by these two threads. One thread runs on the non-static method while another thread runs on the static method.

But the same non-static method or the same static method cannot be accessed concurrently. For example, one thread runs m1(), another thread cannot run m1() at the same time.

Correct me if I am wrong.
 
Ritesh Somani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for helping me out...!

Good Day

Thanks and Regards
-Ritesh Somani
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic