在 Java 中的特定时间运行程序或方法 [英] Run a program or method at specific time in Java

查看:74
本文介绍了在 Java 中的特定时间运行程序或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望我的程序或方法应该在特定的日期和时间运行.我听说过 Java API 中的 Timer 和 TimerTask.但是不知道具体怎么用.

I just want that my program or method should run at specific date and time. i have heard about Timer and TimerTask in java API. But don't know exactly how to use it.

推荐答案

如果您想在特定时间运行 Java 程序,您可能需要查看操作系统工具(如 cron 或 at).

If you want to run a java program at a specific time you probably want to look at the OS tools (like cron or at).

如果你想在已经运行的 java 应用程序中运行一个方法,那么 ScheduleExecutorService,虽然它可能有点矫枉过正,但很容易使用.

If you want to run a method inside of an already running java application then the ScheduleExecutorService, while it may be overkill, is pretty easy to use.

这篇关于在 Java 中的特定时间运行程序或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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