wuqiu-ai / daily-interviews

java面试之每日一练
0 stars 0 forks source link

[线程] 第10天 notify和notifyall的区别 2020-09-06 #68

Open wuqiu-ai opened 4 years ago

wuqiu-ai commented 4 years ago

notify和notifyall的区别?

wuqiu-ai commented 4 years ago
  1. 锁池(获取锁的池子),等待池(调用对象wait()方法后进入等待池);
  2. notifyall会让所有等待池中的线程全部进入锁池去竞争获取锁的机会;
  3. notify只会随机选取一个处于等待池中的线程进入锁池去竞争获取锁的机会;