package TestThread.ThreadSynchronized;
public class TestWaitAll {
public static void main(String[] args) {
Test1 test1 = new Test1();
Thread t = new Thread(test1, "线程1");
Thread t1 = new Thread(test1, "线程2");
Thread t2 = new Thread(test1, "线程3");
Test2 test2 = new Test2(test1, "唤醒线程");
t.start();
t1.start();
t2.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
test2.start();
}
}
class Test1 implements Runnable {
public void run() {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + "当前没有被执行到!");
}
}
}
class Test2 extends Thread {
private Test1 test1;
String name;
public Test2(Test1 test1, String name) {
super(name);
this.name = name;
this.test1 = test1;
}
public void run() {
synchronized (test1) {
test1.notifyAll();// 针对当前对象执行唤醒所有线程的操作
System.out.println(Thread.currentThread().getName() + ":唤醒线程执行成功!");
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有