|
Good day, all.
I'm new to multi-thread and cannot emulate this issue properly, so if anyone could help by comment, I would appreciate much.
The question is, whether synchronized keyword is needed in non-static methods of singleton ?
E.g.
public class MySingleton {
private static MySingleton instance;
public static synchronized MySingleton getInstance() {
if (instance == null) {
instance = new MySingleton();
}
return instance;
}
public void myMethod() {
// do something
}
}
Does method myMethod need to be synchronized or not ?
|