Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update creating mechanism. #1

Merged
merged 11 commits into from
Sep 9, 2014
Next Next commit
Update IvoryTower.java
  • Loading branch information
yusufaytas committed Sep 6, 2014
commit 0509e48d37d981ccdf60b252a263af561f0f08a0
8 changes: 5 additions & 3 deletions singleton/src/main/java/com/iluwatar/IvoryTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
*/
public class IvoryTower {

private static IvoryTower instance = new IvoryTower();
private static IvoryTower instance;

private IvoryTower() {
}
private IvoryTower() {}

public static IvoryTower getInstance() {
if(instance == null){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lazy initialization of the object introduces concurrent access problem (the access to the singleton object is not thread safe anymore).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, I can avoid that with locking but it's not super important though. :) I'll skip this update.

instance = IvoryTower();
}
return instance;
}
}