• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • 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.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic