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

📄 stack.java

📁 操作系统的部分实验源码 希望你们会喜欢 学操作系统必备的
💻 JAVA
字号:

public class Stack 
{
	private int length;
	private int MAX_SIZE=5;
	private String data[];
	public Stack()
	{
		length=0;
		data=new String[MAX_SIZE];
	}
	
	public synchronized void push(String str)
	{
		while(length==MAX_SIZE-1)
		{
			try 
			{
				System.out.println("product wrong wait!");
				this.wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		this.notify();
		data[length]=str;
		length++;
	}
	
	public synchronized String get()
	{
		while(length==0)
		{
			try 
			{
				System.out.println("get wrong wait!");
				this.wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		this.notify();
		length--;
		return data[length+1];
	}
	
	public int getLength()
	{
		return length;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -