62,620
社区成员
发帖
与我相关
我的任务
分享public class ThreadMainDemo implements Runnable{
private Thread mainThread;
public ThreadMainDemo(Thread main){
mainThread = main;
}
public void run(){
while(true){
System.out.println("主线程是否存活" + mainThread.isAlive());
}
}
public static void main(String[] args){
System.out.println("main线程开始");
System.out.println("子线程开始");
new Thread(new ThreadMainDemo(Thread.currentThread())).start();
try{
Thread.sleep(100);
}catch(Exception e){
}
System.out.println("main线程结束");
}
}