Yuta HIGUCHI

Fixed potentially thread unsafe initialization.

Change-Id: I047bcd9358a544723603a069faa234c00ba6b757
......@@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public final class ApplicationId {
private static AtomicInteger idDispenser;
private static final AtomicInteger ID_DISPENCER = new AtomicInteger(1);
private final Integer id;
// Ban public construction
......@@ -50,10 +50,7 @@ public final class ApplicationId {
* @return app id
*/
public static ApplicationId getAppId() {
if (ApplicationId.idDispenser == null) {
ApplicationId.idDispenser = new AtomicInteger(1);
}
return new ApplicationId(ApplicationId.idDispenser.getAndIncrement());
return new ApplicationId(ApplicationId.ID_DISPENCER.getAndIncrement());
}
}
......
......@@ -8,7 +8,7 @@ import org.jboss.netty.util.HashedWheelTimer;
*/
public final class Timer {
private static HashedWheelTimer timer;
private static volatile HashedWheelTimer timer;
// Ban public construction
private Timer() {
......@@ -21,10 +21,16 @@ public final class Timer {
*/
public static HashedWheelTimer getTimer() {
if (Timer.timer == null) {
initTimer();
}
return Timer.timer;
}
private static synchronized void initTimer() {
if (Timer.timer == null) {
Timer.timer = new HashedWheelTimer();
Timer.timer.start();
}
return Timer.timer;
}
}
......