线程 wait notifyAll
来源:互联网 发布:淘宝购物车不能结算 编辑:程序博客网 时间:2024/06/10 18:27
public class Resource {
private static final int size = 10;
private List<String> container = new ArrayList<String>(size);
public synchronized void get() throws InterruptedException {
if (container.isEmpty()) {
System.out.println(Thread.currentThread().getName() + " waited");
this.wait();
System.out.println("test can execute ? ");
}else{
int size2 = container.size();
container.remove(size2 - 1);
System.out.println(Thread.currentThread().getName() + "Real get..");
}
}
public synchronized void put() throws InterruptedException {
if (container.size() > 10) {
this.wait();
}
System.out.println("NotifyAll executed");
container.add("1");
notifyAll();
System.out.println(" Notifall continue ;");
}
}
private static final int size = 10;
private List<String> container = new ArrayList<String>(size);
public synchronized void get() throws InterruptedException {
if (container.isEmpty()) {
System.out.println(Thread.currentThread().getName() + " waited");
this.wait();
System.out.println("test can execute ? ");
}else{
int size2 = container.size();
container.remove(size2 - 1);
System.out.println(Thread.currentThread().getName() + "Real get..");
}
}
public synchronized void put() throws InterruptedException {
if (container.size() > 10) {
this.wait();
}
System.out.println("NotifyAll executed");
container.add("1");
notifyAll();
System.out.println(" Notifall continue ;");
}
}
0 0
- 线程 wait notifyAll
- 线程wait-notify-notifyAll
- java线程wait、notify、notifyAll
- java线程之wait、notifyAll
- JAVA -- 线程wait()、notify()、notifyAll()
- JAVA线程 -- wait notify notifyAll
- java线程:wait,notify,notifyAll
- 关于线程同步通信 wait() notify() notifyAll()
- wait notify notifyall 线程同步方法简述
- 【java】线程同步(synchronized,wait,notify,notifyAll)
- java线程同步(synchronized,wait,notify,notifyAll)
- Java线程_Notify,NotifyAll,Wait方法
- java线程间协作【wait(),notifyAll()】
- 线程同步之wait,notify,notifyall
- Java 线程wait, notify and notifyAll 示例
- Java线程中的wait, notify and notifyAll
- JAVA线程间协作:wait.notify.notifyAll
- 线程同步notify,notifyall,wait探究
- 终期总结
- 热门股票贴士!股票随时会爆炸
- 使用sqoop工具进行数据表增量导入
- 兄弟们都笑了3
- UVA - 10624 Super Number(回溯)
- 线程 wait notifyAll
- xStream转换XML、JSON
- 兄弟们都笑了3
- [C++] 使用C++的三条建议——《C陷阱与缺陷》
- 使用SQL进行递归查询
- CodeForces - 369E Valera and Queries 离线+树状数组
- coursera
- 【C++】输出比输入数值小的所有素数(数据结构实验1)
- Android的PopupWindow弹窗(以常见的分享界面为例)