⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage.java

📁 java的线程类演示
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -