• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Static and non Static Synchronize Methods

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!