• 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

Static and non Static Synchronize Methods

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

Is there any behavioral difference in synchronize static method and synchronize non static method, in a multi threaded environment.

Please explain.

Thanks
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer is yes .

when a synchronize static method is called a lock is obtained on the Class (since static method can be called without creating the clas object) but when a synchronize method is called a lock is obtained on the object which has called the method.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any change in synchronization mechanism both cases(static / non static method) ???
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[message edit: There is no change in synchronization mechanism both cases(static / non static method)]


This does not show the problem well, but when you start doing things like this it is not difficult to have variables such as name in Object one change in ways that are not expected. Not really any change in syntax or meaning of synchronized in either static or instance method.
[ April 16, 2008: Message edited by: Nicholas Jordan ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic