Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 java 控制台应用程序,它将作为守护进程运行,我想使用 Timer.schedule 每隔 n 秒执行一次任务。
Timer timer = new Timer(true); timer.schedule(new ATask(), 0,10000); //insert block here
“阻止”退出的最佳方法是什么?
试试Thread#join()你当前的线程。
Thread#join()
Timer timer = new Timer(true); timer.schedule(new ATask(), 0,10000); Thread currentThread = Thread.currentThread(); currentThread.join();