62,614
社区成员
发帖
与我相关
我的任务
分享
public class DaemonThreadTest extends Thread{
private int no;
public DaemonThreadTest(int no) {
this.no = no;
}
@Override
public void run() {
try {
Thread.sleep(2000);
File f = new File("H:\\decisci\\temp\\f"+no+".txt");
if(! f.exists()){
f.createNewFile();
}
System.out.println("thread ended");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
for(int i=0; i<5; i++){
Thread thread = new DaemonThreadTest(i);
thread.setDaemon(true);
thread.start();
System.out.println("thread "+i+" start");
}
}
}