class TryThread extends Thread
{
int time;
TryThread(int time)
{
this.time=time;
}
public void run()
{
try
{
for(int i=0;i<30;i++)
System.out.println("我是线程甲,是守护线程");
sleep(time);
}
catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
}
class TryThread2 extends Thread
{
int time;
TryThread2(int time)
{
this.time=time;
}
public void run()
{
try
{
for(int i=0;i<30;i++)
System.out.println("我是线程乙,是用户线程");
sleep(time);
}
catch(InterruptedException e)
{
System.out.println(e.toString());
}
}
}
public class Xiancheng implements Runnable
{
public static void main()
{
Thread read=new TryThread(163);
Thread read2=new TryThread2(2004);
read.setDaemon(true);
read2.setDaemon(false);
read.start();
read2.start();
Xiancheng a=new Xiancheng();
Thread b=new Thread(a);
b.start();
}
public void run()
{
try
{
for(int i=0;i<30;i++)
{
System.out.println("我是主线程");
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}