第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

對(duì)于notify()/wait()的一點(diǎn)疑惑

對(duì)于notify()/wait()的一點(diǎn)疑惑

Qyouu 2019-03-01 11:02:31
class MyObject{ private Queue<String> queue = new ConcurrentLinkedQueue<String>(); public synchronized void set(String s){ while(queue.size() >= 10){ try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } queue.add(s); notify(); } } class Producer implements Runnable{ private MyObject myObj; public Producer(MyObject myObj) { this.myObj= myObj; } @Override public void run() { // 每條線程執(zhí)行30次set for (int i = 0; i < 30; i++) { this.myObj.set("obj:" + i); } } } public static void main(String[] args){ Producer producer = new Producer(new MyObject()); // 生成30條線程 for (int i = 0; i < 10; i++) { Thread thread = new Thread(producer); thread.start(); } // 運(yùn)行結(jié)果是只set了30次 } 我的疑惑是notify()發(fā)布通知,為什么不會(huì)讓其他線程的wait()方法繼續(xù)執(zhí)行下去呢?
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 426 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)