runnable.java

来自「学了2个月java 练习用~ 可以看下 希望同意」· Java 代码 · 共 53 行

JAVA
53
字号
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 + =
减小字号Ctrl + -
显示快捷键?