你能用Java重复执行一个任务吗?
是否可以每年,每分钟,每秒,每年重复执行一项任务?我希望它像守护进程一样运行。
Is it possible to repeatedly execute a task each day, each minute, each second, each year? I want it to run like a daemon.
我需要一个计划任务来连续搜索数据库;如果它找到某个值,那么它应该执行另一个任务。
I need a scheduled task to search the database continuously; if it finds a certain value then it should execute a further task.
我想问一下是否可以重复
I want to ask whether it is possible to repeatedly
您可以使用循环,ScheduleExecutorService,Timer或Quartz。
You can use a loop, or a ScheduleExecutorService, or a Timer, or Quartz.
每一天每一秒每一天
each day each minute each second each year
所以每秒一次。
我希望它像守护进程一样运行。
I want it to run like a daemon.
然后我会把它变成一个守护程序线程。不需要让它像一个守护进程。
I would just make it a daemon thread then. No need to make it "like" a daemon.
如果找到正确的值,那么它应该执行剩余的任务。
if it find the correct value then it should do the remaining task.
足够简单。
读取数据,检查数值以及它是什么想要做其余的事。
Read the data, check the value and if its what you want do the rest.