一個簡單的計數器
public class TestMain {
int i =
public static void main(String[] args) {
TestMain c = new TestMain();
Worker x = new Worker(c);
for (int i=
new Thread(x)
}
while (true) { //每隔一秒中輸出計數器的值
System
try {
Thread
} catch (InterruptedException e) {
}
}
}
}
class Worker implements Runnable {
TestMain c;
public Worker(TestMain c) {
this
}
public void run() {
try {
Thread
} catch (InterruptedException e) {
}
c
}
}
上面的程序
c
本來我以為Java裡面++是原子的呢
解決方法
From:http://tw.wingwit.com/Article/program/Java/gj/201311/11157.html