synchronized到底锁住的是谁?
本文代码仓库: https://github.com/yu-linfeng/BlogRepositories/tree/master/repositories/sync 先来一道 校招级 并发编程笔试题 题目:利用5个线程并发执行,num数字累计计数到10000,并打印。 1 /** 2 * Description: 3 * 利用5个线程并发执行,num数字累加计数到10000,并打印。 4 * 2019-06-13 5 * Created with OKevin. 6 */ 7 public class Count { 8 private int num = 0; 9 10 public static void main(String[] args) throws InterruptedException { 11 Count count = new Count(); 12 13 Thread thread1 = new Thread(count.new MyThread()); 14 Thread thread2 = new Thread(count.new MyThread()); 15 Thread thread3 = new Thread(count.new MyThread()); 16 Thread thread4 = new Thread(count.new