example9_20.java.bak

来自「不错的教程 适合中高级人员的使用」· BAK 代码 · 共 44 行

BAK
44
字号

public class Example9_20 
{
	 public static void main(String args[])
   {  Daemon=new Daemon();
	 a.A.start();
	 a.B.setDaemon(true);
	 a.B.start();
   }
}
class Daemon implements Runnable
{
	Thread A,B;
	Daemon()
	{
		A=new Thread(this);
		B=new Thread(this);
	}
	public void run()
	{
		if(Thread.currentThread()==A)
		{
			for(int i=0;i<=8;i++)
			{System.out.println("i="+i);
			try{Thread.sleep(1000);
			}
			catch(InterruptedException e){}
			}			
		}
		else if(Thread.currentThread()==B)
		{
			while(true)
			{
				System.out.println("线程B是守护线程");
				try{Thread.sleep(1000);
			     }
			    catch(InterruptedException e){}			   
			}
		}

		}
	}

⌨️ 快捷键说明

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