I have one class that is the below one..
public class DataBaseDAO {
private DataBaseDAO() { }
public static synchronized DataBaseDAO getInstance() {
if (dao == null) {
dao = new DataBaseDAO();
}
return dao;
}
}
}
Now this getinstance() method can be hacked: In other words this singleton can be hacked and more objects could be created.
How can I make this secure?
This can be broken through reflection, classloaders and deserilizaton.
Should I go for synchronized block instead of putting synchronization on whole method?
Will it make impact on the performance?
Thanks folks ,actually I don't want to introduce the new enum since in existing structure then many changes will take place , I was looking how can I IMPROVE THE EXISTING SINGLETON WITH THE CURRENT APPROACH OF WITHIN CLASS ITSELF..!!