thread safety bug (#1988)

pull/2004/head
XenoAmess 3 years ago committed by GitHub
parent cbc6402035
commit 52274ff63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;
import static com.taobao.arthas.core.command.model.MemoryEntryVO.TYPE_BUFFER_POOL;
import static com.taobao.arthas.core.command.model.MemoryEntryVO.TYPE_HEAP;
@ -66,7 +67,7 @@ public class DashboardCommand extends AnnotatedCommand {
private long interval = 5000;
private volatile long count = 0;
private final AtomicLong count = new AtomicLong(0);
private volatile Timer timer;
@Option(shortName = "n", longName = "number-of-execution")
@ -297,7 +298,7 @@ public class DashboardCommand extends AnnotatedCommand {
@Override
public void run() {
try {
if (count >= getNumOfExecutions()) {
if (count.get() >= getNumOfExecutions()) {
// stop the timer
timer.cancel();
timer.purge();
@ -329,7 +330,7 @@ public class DashboardCommand extends AnnotatedCommand {
process.appendResult(dashboardModel);
count++;
count.getAndIncrement();
process.times().incrementAndGet();
} catch (Throwable e) {
String msg = "process dashboard failed: " + e.getMessage();

@ -6,6 +6,7 @@ import com.taobao.middleware.cli.CommandLine;
import com.taobao.middleware.cli.Option;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author ralf0131 2017-02-23 23:28.
@ -17,7 +18,7 @@ public class WordCountHandler extends StdoutHandler implements StatisticsFunctio
private boolean lineMode;
private String result = null;
private volatile int total = 0;
private final AtomicInteger total = new AtomicInteger(0);
public static StdoutHandler inject(List<CliToken> tokens) {
List<String> args = StdoutHandler.parseArgs(tokens, NAME);
@ -39,7 +40,7 @@ public class WordCountHandler extends StdoutHandler implements StatisticsFunctio
result = "wc currently only support wc -l!\n";
} else {
if (input != null && !"".equals(input.trim())) {
total += input.split("\n").length;
total.getAndAdd(input.split("\n").length);
}
}
@ -52,6 +53,6 @@ public class WordCountHandler extends StdoutHandler implements StatisticsFunctio
return result;
}
return total + "\n";
return total.get() + "\n";
}
}

Loading…
Cancel
Save