Skip to content

Commit

Permalink
Fixes #3: InitExecutor state check not thread-safe
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
  • Loading branch information
sczyh30 committed Jul 24, 2018
1 parent 9556ecc commit 4612303
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicBoolean;

import com.alibaba.csp.sentinel.log.RecordLog;

Expand All @@ -13,14 +14,14 @@
*/
public final class InitExecutor {

private static volatile boolean initialized = false;
private static AtomicBoolean initialized = new AtomicBoolean(false);

/**
* If one {@link InitFunc} throws an exception, the init process
* will immediately be interrupted and the application will exit.
*/
public static void doInit() {
if (initialized) {
if (initialized.compareAndSet(false, true)) {
return;
}
try {
Expand All @@ -32,7 +33,6 @@ public static void doInit() {
for (OrderWrapper w : initList) {
w.func.init();
}
initialized = true;
} catch (Exception ex) {
RecordLog.info("[Sentinel InitExecutor] Init failed", ex);
ex.printStackTrace();
Expand Down

0 comments on commit 4612303

Please sign in to comment.