Refactor thread-safety on MainWindow.getInstance()
This removes an unneeded lock object, replacing it with a traditional synchronized keyword.
No functional changes should be introduced by this change.
@@ -83,7 +83,6 @@ public final class MainWindow extends ChatFrame implements ActionListener {
private JEditorPane aboutBoxPane;
private static MainWindow singleton;
- private static final Object LOCK = new Object();
/**
* Returns the singleton instance of <CODE>MainWindow</CODE>,
@@ -92,13 +91,10 @@ public final class MainWindow extends ChatFrame implements ActionListener {
*
* @return the singleton instance of <Code>MainWindow</CODE>
*/
- public static MainWindow getInstance() {
- // Synchronize on LOCK to ensure that we don't end up creating two singletons.
- synchronized (LOCK) {
+ public static synchronized MainWindow getInstance() {
if (null == singleton) {
singleton = new MainWindow(Default.getString(Default.APPLICATION_NAME), SparkManager.getApplicationImage());
}
- }
return singleton;
}
