我们先看一段代码:
启动两在这里插入代码片
个线程,每个线程中让静态变量count循环累加100次。
public class Te{
public static int count =0;
public static void main(String[] args) {
for (int i = 0; i < 2; i++) {
new Thread(
new Runnable() {
public void run() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (int j = 0; j < 100; j++) {
count++ ;
}
}
}
).start();
}
try