| Author |
thread safe singleton class
|
bjit babu
Greenhorn
Joined: Mar 25, 2010
Posts: 10
|
|
|
what is the best possible way to make a singleton class thread safe.
|
 |
Pat Farrell
Rancher
Joined: Aug 11, 2007
Posts: 4422
|
|
Don't use a singleton class. Singletons are evil.
They can be thread safe if you make the data in them immutable.
|
 |
Alexey Dubinin
Greenhorn
Joined: Mar 23, 2010
Posts: 2
|
|
The simplest way is to use enum:
But remember that methods of this class should be thread safe.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3044
|
|
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.
|
 |
 |
|
|
subject: thread safe singleton class
|
|
|