[英]Prevent exiting scheduled task
I have java console application what will run as daemon where I want to use Timer.schedule to execute task every n seconds. 我有一个Java控制台应用程序,它将作为守护程序运行,我想在其中使用Timer.schedule每n秒执行一次任务。
Timer timer = new Timer(true);
timer.schedule(new ATask(), 0,10000);
//insert block here
What is the best way to "block" from exiting? “阻止”退出的最佳方法是什么?
try Thread#join()
your current Thread. 尝试
Thread#join()
您当前的线程。
Timer timer = new Timer(true);
timer.schedule(new ATask(), 0,10000);
Thread currentThread = Thread.currentThread();
currentThread.join();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.