看板java
标 题Re: [问题] MultiThread 请问彼此间要如何沟通呢~~
发信站无名小站 (Thu Jun 15 07:26:03 2006)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!news.ee.ttu!netnews.csie.nc
如果用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的意思。
※ 引述《[email protected] (贱兔..><)》之铭言:
> ※ 引述《[email protected] (飞)》之铭言:
> : 不了解您的意思,
> : 原po应该没要求suspend/resume某个thread.
> 他的意思应该是在 thread 中这样做...
> while(locked==true) wait();
> locked = true;
> // do something...
> locked = false;
> OS 课本也不错
--
夫兵者不祥之器物或恶之故有道者不处君子居则贵左用兵则贵右兵者不祥之器非君子
之器不得已而用之恬淡为上胜而不美而美之者是乐杀人夫乐杀人者则不可得志於天下
矣吉事尚左凶事尚右偏将军居左上将军居右言以丧礼处之杀人之众以哀悲泣之战胜以
丧礼处之道常无名朴虽小天下莫能臣侯王若能守之万物将自宾天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦将知止知止可以不殆譬道之在天下犹 tm.net.my海