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

📄 extendsthread.java

📁 学了2个月java 练习用~ 可以看下 希望同意
💻 JAVA
字号:
import java.io.*;

public class extendsThread
{
	public static void main(String[] args)
	{
		newThread one=new newThread("aaa");
		newThread two=new newThread("bb");
		one.setanother(two);
		two.setanother(one);

		one.start();
		two.start();
	}
}

class newThread extends Thread{
	newThread another;
	int i=1;

	public newThread(String name){
		super(name);
	}

	public void setanother(newThread now){
		another=now;
	}
	public void run (){
		for (i=1;i<=500 ;i++ ){

			System.out.println(getName()+" "+i+" "+another.isAlive());
			if(i==200&&another.isAlive()&&another.i!=200){
				try{
					another.join();
				}
				catch (Exception e){
				}
			}
		}
	}
	public void testjoin(){
		try{
			another.join();
		}
		catch (Exception e2){
			System.out.println(another.getName());
		}
	}
}

⌨️ 快捷键说明

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