你能用Java重复执行一个任务吗? [英] Can you execute a task repeatedly in Java?

查看:643
本文介绍了你能用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.

这篇关于你能用Java重复执行一个任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆