当调度程序在 Spring Boot 应用程序中启动时,我可以获得以毫秒为单位的时间吗
我有一个方法,它将以 2 小时的间隔运行,并在 Spring boot 应用程序中的 Scheduler 的 cron 中提到。 现在我的问题是我可以获得调度程序运行时的时间(以毫秒为单位)吗?
我试图获取时间,但在调度程序运行时无法获取它。
I have a method which will be running at an interval of 2 hrs and is mentioned in cron of Scheduler in Spring boot application.
Now my question is can I get the time in milliseconds when the scheduler ran?
I tried to get the time but not able to fetch it when the scheduler ran.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring调度器指南给出了类似的例子,请参阅链接:https://spring.io /guides/gs/scheduling-tasks/ 。
您可以将时间记录到日志文件中,但正如托马斯提到的,确切的执行时间可能是在几毫秒之后(与机器和线程调度程序以及线程执行日志任务或打印到输出流所需的时间有关) 。
The Spring guide of scheduler give a similar example , see the link : https://spring.io/guides/gs/scheduling-tasks/ .
You can log the time to a logFile but as Thomas mention the exact time of execution may be after some millisonconds (related with the machine and the thread scheduler and the time needed by the thread to do the task of log or print to the outputStream).