62,623
社区成员
发帖
与我相关
我的任务
分享class Test implements Runnable {
public void run() {
try {
while (true) {
System.out.print(1);
synchronized (this) {
wait();
notify();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class bk {
public static void main(String[] args) {
Test t = new Test();
new Thread(t).start();
}
}class Test implements Runnable {
public void run() {
try {
while (true) {
System.out.print(1);
synchronized (this) {
this.wait();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class Test1 implements Runnable {
private Test test = null;
Test1(Test t){test = t;}
public void run() {
while (true) {
synchronized (test) {
test.notify();
}
}
}
}
public class bk {
public static void main(String[] args) {
Test t = new Test();
new Thread(t).start();
Test1 t1 = new Test1(t);
new Thread(t1).start();
}
}