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 ;");
}
}