Kuma Phani wrote:Yes, instance variable in enum is threadsafe.
public enum BMW{
INSTANCE;
}
INSTANCE - is thread safe.
FALSE
No variable or object in
Java is intrinsically threadsafe. If an object is accessible by 2 different threads, they can totally slaughter it.
To be threadsafe, mechanisms must be employed to enforce threadsafe access. The most common mechanism used for this purpose is Java's built-in "synchronized" capabilities. You use the "synchronized" modifier to ensure that critical properties, methods, or even the class instance as a while are only accessed according to proper threading protocols.
Nothing is synchronized by default, however.
For an example of a class whose methods have been made threadsafe, look at the java StringBuffer class. Then contrast it with the newer and non-threadsafe StringBuilder class.