• 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

Thread synchronization ..... CIW

 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About thread synchronization I have deduced these things CORRECT ME IF I AM WRONG:
1. method synchronization:
1) No other synchronized method can be executed of the same object if any one synchronized method has acquired monitor.
2. object synchronization:
1) object synchronization is obtained when we acquire a lock on a object i.e


Once we acquire a monitor on object then no other synchronized method or synchronized block of same object can be executed till monitor is released.

3. method synchronization and object synchronization is same i.e they obtain object monitor , only way of implementation is different.
4. class synchronization is achived by synchronizing static method of class i.e.

5. when class monitor is obtained then we can not executed any other synchronized static method of that class, but we can execute any instant method, that instant method could be synchronized and we can execute synchronized block as these monitors are object monitor.
====================================================================
If I am right till now then I have some doubts(again please Correct If Wrong - CIW), PLEASE clear these doubts:
Doubt01. If I have a static member object reference and I get a lock on it then is it a objec monitor or class monitor
exa:


i) IS THIS(block01) A class monitor OR object monitor , as obj is static?
ii) while executing block01 can method01() be executed ?
iii) while executing block01 can staticMethod01() be executed ?
iv) can any other object of MyClass execute thses methods and block?


Doubt02.

i) let us say I have created an object of Class01 and assigned it to object ref 'obj01' of Class01. Now while executing 'block02' can I execute method01() of obj01? I think YES

ii) I think while executing block02 , we can not execute any synchronized method or block of object refernced by oc.

iii) What if I assigned object to some other refernce var and try to execute synchronized method while it is in monitor? I think it will go in wait state as object is same.

Doubt03.
As per my knowledge of point 5.
if we can execute instant synchronized methods of class monitor then if we change any static varible in instant method then there will be data corruption?
I mean:




so when staticMethod01() is in monitor then method01() can be executed by some other thread and as they are sharing data then there will be corruption? Am I right ?


Correct me if I am wrong ....

I know it has become very long ... but i want to clear alll my doubts abt synchronization. For me also it was tiring... hope you all there will understand me.

THANKS in advance !
[ January 17, 2002: Message edited by: ravish kumar ]
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I think I got what I was looking for ... plz visit this and this too as both are related and give almost full information about thread synchronization block or class monitor.
one request ::: plz read full page ... I remember one of my friends advise that even do not beleive God, they also do mistakes. Do it yourself and then beleive(by SAKKU)
AW there Maha also is wrong initially so read full page else you will have confusion like this one.
After reading those links if you guys still have stamina then go through this as this will work as
refresher as there is nice silent(censored) ego clash is going on
Thanks a lot everyone
[ January 17, 2002: Message edited by: ravish kumar ]
 
We noticed he had no friends. So we gave him this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic