package com.thread.daemon;
import java.util.concurrent.TimeUnit;
public class ADaemon implements Runnable
{
@Override
public void run()
{
try
{
System.out.println("Start...");
TimeUnit.MILLISECONDS.sleep(1000);
}
catch (Exception e)
{
System.out.println("catch ...");
}
finally
{
System.out.println("finally ... ");
}
}
public static void main(String[] args)
{
Thread t = new Thread(new ADaemon());
t.setDaemon(true);//注解此行finally中科执行
t.start();
}
}
Daemon守护线程让finally里面的语句不能执行
最新推荐文章于 2022-04-21 04:31:41 发布