Forums Register Login

thread safe singleton class

+Pie Number of slices to send: Send
what is the best possible way to make a singleton class thread safe.
+Pie Number of slices to send: Send
Don't use a singleton class. Singletons are evil.

They can be thread safe if you make the data in them immutable.
+Pie Number of slices to send: Send
The simplest way is to use enum:

But remember that methods of this class should be thread safe.
+Pie Number of slices to send: Send
Singletons or enums aare no different from other classes when it comes to thread-safety.

Either synchronize them properly, or even better, make them immutable.
Acetylsalicylic acid is aspirin. This could be handy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1222 times.
Similar Threads
Is Struts Action class Thread Safe?
question about action class
Singleton Question
Doubt regarding singleton
Singleton Issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:33:18.