• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Threads-synchronisation

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need help in thread synchronisation, just need a clarification can we use synchronised keyword with static methods also if yes, then please explain me with example.
Thanks in advance
 
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Divya,
Refer this link. It will help you.


Regards
Nik
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Divya Gehlot:
...can we use synchronised keyword with static methods...


Yes (if you spell it "synchronized").

Remember, each instance has its own lock, but there is also a class lock. If "synchronized" is used with a static (class) method, then the class lock must be obtained.
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks Nik for provided me link but that discussion is really confusing for me. Can any one please explain me this with simple example.
Thanks in Advance.
[ June 29, 2007: Message edited by: Divya Gehlot ]
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're not sure about the differences between a class lock and an object lock, the now would probably be a good time to work though the Sun Java Thread Tutorial, which explains these concepts, and also has plenty of examples. The chapter on Synchronization is especially relevant.
 
reply
    Bookmark Topic Watch Topic
  • New Topic