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

📄 test.java

📁 学了2个月java 练习用~ 可以看下 希望同意
💻 JAVA
字号:
public class test
{
	public static void main(String[] args)
	{
		testobject a=new testobject();
		testThreadone testone=new testThreadone(a);
		testThreadtwo testtwo=new testThreadtwo(a);
		testone.start();
		testtwo.start();
	}
}

class testobject{
	private int i=0;

	public void seti(int i){
		this.i=i;
	}

	public int geti(){
		return i;
	}
}

class testThreadone extends Thread{
	testobject now;
	public testThreadone(testobject now){
		this.now=now;
	}

	public void run(){
		try{
			if(now.geti()==0) sleep(1000);
		}
		catch (Exception e){
		}
		synchronized(now){
			for (int i=1;i<=100 ;i++ ){
				now.seti(now.geti()+i);
			}
			now.notifyAll();
		}
	}
}

class testThreadtwo extends Thread{
	testobject now;
	public testThreadtwo (testobject now){
		this.now=now;
	}

	public void run(){
		synchronized(now){
			now.seti(10000);
			try{
				now.wait();
				System.out.println(now.geti());
			}
			catch (Exception e){
			}
		}
	}
}

⌨️ 快捷键说明

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