62,635
社区成员




7: getfield #14 // Field sum:I
10: iconst_1
11: iadd
12: putfield #14 // Field sum:I
public class Threads implements Runnable {
public int sum = 0;
/**
* @param args
*/
public static void main(String[] args) {
Threads ts = new Threads();
Thread t1 = new Thread(ts);
Thread t2 = new Thread(ts);
t1.start();
t2.start();
try {
Thread.sleep(5000);//保证两个线程都执行完
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(ts.sum);
}
public void run() {
for (int i = 1; i <= 50; i++) {
sum=sum+i;
}
}
}
sum=2550