Re: [問題] MultiThread 請問彼此間要如何溝通呢~~

看板java作者時間19年前 (2006/06/15 07:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串8/11 (看更多)
如果用wait/notify,根本就沒必要加true/false flag. 我猜他的意思是這樣: class Thread2 { void runningThread2(Thread1 thread1) { //blablabla synchronized(this) { wait(); } String textFieldValue = thread1.getTextField().getText(); } void notifyThread2() { synchronized(this) { notify(); } } } class Thread1 { private Thread2 thread2; private TextField textField; public TextField getTextField() { return textField; } public Thread1(Thread2 thread2) { this.thread2 = thread2; } //while button textField filled up with value and button pressed. void actionPerformed(ActionEvent e) { thread2.notifyThread2(); } } 問題是,原po應該沒要求暫停哪個thread, 除非我誤解了原po or adrianshum的意思。 ※ 引述《Gentoo.bbs@ofo.csie.ntu.edu.tw (賤兔..><)》之銘言: > ※ 引述《feicsh.bbs@bbs.wretch.cc (飛)》之銘言: > : 不瞭解您的意思, > : 原po應該沒要求suspend/resume某個thread. > 他的意思應該是在 thread 中這樣做... > while(locked==true) wait(); > locked = true; > // do something... > locked = false; > OS 課本也不錯 -- 夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子 之器不得已而用之恬淡為上勝而不美而美之者是樂殺人夫樂殺人者則不可得志於天下 矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以 喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫 之令而自均始制有名名亦既有夫亦將知止知止可以不殆譬道之在天下猶 tm.net.my
文章代碼(AID): #14a9nq00 (java)
討論串 (同標題文章)
完整討論串 (本文為第 8 之 11 篇):
文章代碼(AID): #14a9nq00 (java)