BackGroundTread 实现runnable接口
package cn.happy.tread3;
public class BackGroundTread implements Runnable{
@Override
public void run() {
for (int i = 0; i < 100000; i++) {
System.out.println("这是后台线程第"+i+"次执行");
}
}
}
MyTread继承Thread类
package cn.happy.tread3;
public class MyTread extends Thread{
@Override
public void run() {
for (int i = 0; i < 4; i++) {
System.out.println("这是线程第"+i+"次执行");
}
}
}
测试类
package cn.happy.tread3;
public class Test {public static void main(String[] args) {
Thread t1=new MyTread();
Thread t2=new Thread(new BackGroundTread());
t2.setDaemon(true);
t1.start();
t2.start();
}
}