[問題] IllegalMonitorStateException 發生原因?

看板java作者時間16年前 (2007/12/18 21:55), 編輯推噓2(204)
留言6則, 2人參與, 最新討論串1/1
Hi, 我寫多執行緒程式遇到 IllegalMonitorStateException, 為了查明發生的原因, 我查了一下文件: http://tinyurl.com/2h93vm 上面的說明寫道: Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor. 請問「擁有該物件的 monitor」(owning the specified monitor) 是什麼意思? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.164.218

12/18 23:25, , 1F
有沒有寫 synchronized (...) { ... } ?
12/18 23:25, 1F

12/19 14:31, , 2F
ok 我知道為什麼了 3Q
12/19 14:31, 2F

12/19 17:53, , 3F
這個不好解釋,請問你能不能分享一下為什麼會發生嗎...
12/19 17:53, 3F

12/19 20:55, , 4F
就如你所說, obj.wait() 和 obj.notify() 外面一定要包
12/19 20:55, 4F

12/19 20:56, , 5F
synchronized(obj) { ... }
12/19 20:56, 5F

12/19 23:27, , 6F
ok, 感謝您喚起我的回憶
12/19 23:27, 6F
文章代碼(AID): #17Pz5e0X (java)