繁体   English   中英

防止退出计划任务

[英]Prevent exiting scheduled task

我有一个Java控制台应用程序,它将作为守护程序运行,我想在其中使用Timer.schedule每n秒执行一次任务。

Timer timer = new Timer(true);
timer.schedule(new ATask(), 0,10000);   
//insert block here     

“阻止”退出的最佳方法是什么?

尝试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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM