【发布时间】:2023-04-09 09:12:02
【问题描述】:
这是我想做的基本概念
假设我有一个看起来像这样的线程。
public class Thread1 implements Runnable{
run(){
while(true){
//doWork and have thread 2 start working over a TCP connection, in my particular case
wait();
}
}
还有线程 2
public class Thread2 implements Runnable{
run(){
while(true){
//doWork and now I need to wake up thread 1
t1.notify(); //???
}
}
这显然行不通...我的问题是如何使这项工作基本完成。两个线程都是在 main 中创建的,所以我可以给他们任何必要的信息。 任何帮助将不胜感激。
【问题讨论】:
标签: java multithreading wait notify