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

📄 test.java

📁 thread
💻 JAVA
字号:
package com.test2;

import java.util.Stack;
import java.util.Vector;

public class Test {
	
	private int index;

	private int[] is = new int[6];

	public synchronized int pop() {
		while(index == 0){
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		index--;
		int temp = is[index];
		
		notifyAll();
		
		return temp;
	}

	public synchronized void push(int i) {
		while(index == 6){
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		is[index] = i;
		++index;
		
		notifyAll();
	}

	public static void main(String[] args) {
		Test t = new Test();
		T1 t1 = new T1(t);
		T2 t2 = new T2(t);
		t1.start();
		t2.start();
	}

}

⌨️ 快捷键说明

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