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

📄 runnable.java

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

public class runnable
{
	public static void main(String[] args)
	{
		testrunnable now=new testrunnable();
		Thread x=new Thread(now);
		Thread y=new Thread(now);
		x.setName("one");
		y.setName("two");

		x.start();
		y.start();

	}
}

class testrunnable implements Runnable{
	private boolean tf=false;

	public void run(){
		Thread now=Thread.currentThread();

		for (int i=1;i<=100 ;i++ ){
			System.out.println(now.getName()+i+" strat T/F :"+tf);
			if(tf) {break;}
			System.out.println("----------->"+now.getName()+" :"+i+" "+tf);
			if(i==100 && !tf)	{tf=true;}
			System.out.println(now.getName()+i+" end T/F :"+tf);
		}
	}
}

class extendsThread extends Thread{
	private static boolean tf=false;

	public void setnow(boolean a){
		tf=a;
	}

	public void run(){


		for (int i=1;i<=100 ;i++ ){
			if(tf) {break;}

			System.out.println(getName()+" :"+i);

			if(i==100)	setnow(true);
		}
	}
}

⌨️ 快捷键说明

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