直接把運(yùn)行結(jié)束的語句刪掉不妥。
public synchronized void method() {
print(tName() + "開始執(zhí)行");
try {
Thread.sleep(3000);
if (tName().equals("Thread-0")) {
throw new RuntimeException();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
print(tName() + "執(zhí)行結(jié)束");
}
public synchronized void method() {
print(tName() + "開始執(zhí)行");
try {
Thread.sleep(3000);
if (tName().equals("Thread-0")) {
throw new RuntimeException();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
print(tName() + "執(zhí)行結(jié)束");
}
2019-01-30