public class AccountSync implements Runnable{static Integer count = 0;static String str ="111";@Overridepublic 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);}}
請問下這和synchronized鎖為什么沒有起錯用呢
函數(shù)式編程
2018-08-12 07:10:59