public class AccountSync implements Runnable{
static Integer count = 0;
static String str ="111";
@Override
public void run() {
for(int j=0;j<10000000;j++){
synchronized(count){
count++;
}
}
}
// static AccountSync account = new AccountSync();
public static void main(String[] args) throws InterruptedException {
AccountSync account = new AccountSync();
Thread t1 = new Thread(account);
Thread t2 = new Thread(account);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(count);
}
}
手掌心
相关分类