简体   繁体   English

是否可以在特定时间段运行代码?

[英]Is it possible to run a code at certain time period?

So, I am writing a Java code where I want the program to take content from the web every monday 12 am. 因此,我正在编写Java代码,希望该程序每个星期一的12点从网络上获取内容。

I found SO many answers telling me how to run a program for certain amount of time. 我发现这么多的答案告诉我如何运行一定时间的程序。 I want to run the program and execute every monday morning. 我想运行该程序并在每个星期一早上执行。

I want to know if any one has ANY idea where to start? 我想知道是否有人从哪里开始?

I found of AlarmManager for android applications (which is sort what I want) but I want it for Java program not application. 我找到了适用于android应用程序的AlarmManager(这是我想要的),但我希望它适用于Java程序而不是应用程序。

Or is this even possible? 还是有可能吗?

Sure! 当然! If you are on linux or mac, just set up a cronjob to run at 0 0 * * 1 如果您使用的是Linux或Mac,只需设置一个cronjob以0 0 * * 1

It'd be something like: 就像这样:

java MyScript.java

as the task. 作为任务。

http://quartz-scheduler.org/是设置类似cron的作业的标准工具

是的,它正在使用Windows Task Manager!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM