storage.java
来自「java的线程类演示」· Java 代码 · 共 40 行
JAVA
40 行
public class Storage
{
private int count;
private int size;
public Storage(int s)
{
size = s;
}
public synchronized void addData(String n)
{
while (count == size)
{
try {
this.wait();
}
catch (InterruptedException e) { }
}
this.notify();
count++;
System.out.println(n+" make data count: "+count);
}
public synchronized void delData(String n)
{
while (count == 0)
{
try {
this.wait();
}
catch (InterruptedException e) { }
}
this.notify();
System.out.println(n+" use data count: "+count);
count--;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?