Skip to content

Commit

Permalink
use double check lazy to get AuroraLoggerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
InkerBot committed Jun 25, 2024
1 parent 8d2a481 commit 2fd49cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ public class AuroraLoggerFactory implements ILoggerFactory {
private Function<String, String> nameMapping;
private int currentVersion = 0;

public AuroraLoggerFactory() {
if (INSTANCE != null) {
throw new IllegalStateException("AuroraLoggerFactory is a singleton");
}
INSTANCE = this;
private AuroraLoggerFactory() {
this.nameMapping = Function.identity();
this.provider = selectDefaultProvider();
}

public static AuroraLoggerFactory instance() {
return INSTANCE;
AuroraLoggerFactory instance = INSTANCE;
if (instance == null) {
synchronized (AuroraLoggerFactory.class) {
instance = INSTANCE;
if (instance == null) {
instance = new AuroraLoggerFactory();
INSTANCE = instance;
}
}
}
return instance;
}

private ILoggerFactory selectDefaultProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static final StaticLoggerBinder getSingleton() {
private final ILoggerFactory loggerFactory;

private StaticLoggerBinder() {
loggerFactory = new AuroraLoggerFactory();
loggerFactory = AuroraLoggerFactory.instance();
}

public ILoggerFactory getLoggerFactory() {
Expand Down

0 comments on commit 2fd49cc

Please sign in to comment.