1 Star 0 Fork 0

schwarizard / Chapter 11

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
Variable2Test 638 Bytes
Copy Edit Raw Blame History
schwarizard authored 2016-04-11 19:49 +08:00 . new file
class Variable2 {
static int i = 0, j = 0;
static synchronized void one() {
i++;
j++;
}
static synchronized void two() {
System.out.printf("i = %d, j = %d%n", i, j);
}
}
public class Variable2Test {
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
while (true) {
Variable2.one();
}
});
Thread thread2 = new Thread(() -> {
while (true) {
Variable2.two();
}
});
thread1.start();
thread2.start();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/schwarizard/Chapter-11.git
git@gitee.com:schwarizard/Chapter-11.git
schwarizard
Chapter-11
Chapter 11
master

Search