menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

A More Rel...
source image

Medium

1w

read

127

img
dot

A More Reliable Thread-Save Java Singleton Class Implementation

  • The constructor is made private to prevent the class user from creating instances of the class using the 'new' keyword.
  • The previous class implementation was not thread-safe, but the new version is more reliable in a multi-threaded environment.
  • The use of a local variable 'result' improves code performance. In most cases, the volatile field is only accessed once, resulting in a potential 25 percent performance improvement.
  • The mutex object is not a string to avoid locking a string that might be used by another piece of code. String objects are stored in a string pool.

Read Full Article

like

7 Likes

For uninterrupted reading, download the app