私はmyThread.wait()
それがsynchronzed(myThread)
ブロックされています。そして、ランナブルを実装する Myrunner があります。myRunnerから伝えたいのnotify()
ですが、監視対象ではありません。myRunnable から myThread のハンドルを取得して通知することは可能ですか? 他の解決策はありますか?私のコード固有に関連するいくつかの理由から、拡張myRunnable
して実行するのは良くありません。Thread
public class ThreadMain {
public Thread reader;
private class SerialReader implements Runnable {
public void run() {
while (true) {
try {
Thread.sleep(3000);
synchronized(this) {
System.out.println("notifying");
notify();
System.out.println("notifying done");
}
} catch (Exception e) {
System.out.println(e);
}
}
}
}
ThreadMain() {
reader = new Thread(new SerialReader());
}
public static void main(String [] args) {
ThreadMain d= new ThreadMain();
d.reader.start();
synchronized(d.reader) {
try {
d.reader.wait();
System.out.println("got notify");
} catch (Exception e) {
System.out.println(e);
}
}
}
}