• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

RenentrantReadWriteLock on static method

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to see the difference between "applying a ReentrantReadWriteLock to a static method" and "applying a ReentrantReadWriteLock to a non-static method". I thought it should be the same, but somehow I thought it should have some difference. I got myself in a unclear state. Can anyone help me out? By the way, I defined these set of static methods in a cache utility class to add/remove/invalidate cache.

or this is a lower level question? what the pro and cons on static method comparing to regular method in a multi-threaded environment?

Thank you

-Rick
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ricky:what the pro and cons on static method comparing to regular method in a multi-threaded environment?



I dont think there is a point in talking about methods being static or not, it is the data that is to be made threadsafe. Any data in a multi-threaded environment must be protected using various synchronization technique.
Static data is shared by all the instances of the class (or by calling programs if there are no instances) So, when there are a lot of instances of a class, static data it is more prone to corruption by multiple threads as compared to instance data.
Other than this there is no real difference in making a static/instance data threadsafe.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic