我正在尝试Spring 3的@Scheduled注释.这是我的配置(app.xml):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
"
>
<context:component-scan base-package="destiny.web"/>
<context:annotation-config/>
// other beans
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
<task:executor id="myExecutor" pool-size="5"/>
<task:scheduler id="myScheduler" pool-size="10"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
这是我的服务类:
@Service
public class ServiceImpl implements Service , Serializable
{
//other injections
@Override
@Transactional
public void timeConsumingJob()
{
try
{
Thread.sleep(10*1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
@Override
@Scheduled(cron="* * * * * ?")
public void secondly() …
Run Code Online (Sandbox Code Playgroud) 我需要在每个月的最后一天开始工作.我尝试了以下cron表达式:
<property name="cronExpression" value="0 0 3 L * * *" />
Run Code Online (Sandbox Code Playgroud)
但得到了这个错误:
Caused by: java.lang.UnsupportedOperationException: Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
Run Code Online (Sandbox Code Playgroud)
它不喜欢它L
,但没有使用它,我怎么能在这个月的最后一天运行?
嗨我想在每天中午使用cron job进行数据库备份...并且数据库备份的名称应附加当前日期...备份文件的格式应为mydata_yyyy_mm_dd.sql ...备份文件应放在/根目录
Java中有没有办法从Cron Expression中找到"Last Fired Time".
例如,如果现在= 2010年4月25日晚上10点,cron表达"0 15 10?**"(石英)应该会回复我25-Apr-2010 10:15 am
注意:1)我不关心我们是否使用标准cron表达式(如Unix和Quartz)或不那么受欢迎的表达式,如果他们可以获取正确的"最后发射时间"2)它也不是字面上的"最后一次发射时间"作为触发器可能没有触发,但逻辑上应该有一种方法可以告诉它(最终会)触发的时间.
我正在使用Quartz Scheduler v.1.8.0.
如何获取已分配/附加到作业并使用CronTrigger计划的cron表达式?在这种情况下,我有工作名称和组名.虽然很多触发器可以指向同一个Job,但就我而言,它只有一个.
有一个在调度器类,可用的一种方法Scheduler.getTriggersOfJob(JOBNAME,组名),但它仅返回触发器阵列.
示例cronexpression: 0 /5 10-20 * * ?
注意:CronTrigger类扩展了Trigger
我需要在特定日期和时间向几个手机号码发送短信。例如,我将有一个日期和时间列表以及相应的手机号码列表。如下。
Date Mobile
10th April 9 AM 1234567890
10th April 11 AM 9987123456,9987123457
11th April 3.30 PM 9987123456
Run Code Online (Sandbox Code Playgroud)
等等。
我知道,java 有可以按特定时间表运行的 cron 调度程序。
http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
我可以运行一个可以继续检查时间的工作,然后如果当前时间与上面列表中的时间匹配,则发送短信。
但在这种情况下,我将不得不一直检查。
有什么办法,我可以在给定的时间直接触发这些事件/短信。类似于为每个日期时间注册作业并在那个时间解雇那些作业,而不是让作业连续运行以检查日期时间?
我正在尝试使用 jenkins job dsl 添加参数化的 cron 作业。但是,每次我尝试添加作业时都会看到以下错误:
No signature of method: javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.parameterizedTimerTrigger() is applicable
for argument types: (com.manh.cp.jenkins.script$_createJob_closure3$_closure6$_closure9) values:
[com.manh.cp.jenkins.script$_createJob_closure3$_closure6$_closure9@4f7fa1a2]
Run Code Online (Sandbox Code Playgroud)
我都尝试过:
triggers {
parameterizedCron('''H 20 * * * %var=a''')
}
Run Code Online (Sandbox Code Playgroud)
和
triggers {
parameterizedTimerTrigger {
parameterizedSpecification('H 20 * * * %var=a')
}
}
Run Code Online (Sandbox Code Playgroud)
这对其他人还有效吗
参数化调度程序 v0.8 作业 dsl v1.76
我将 JDBC 作业存储与quartz 一起使用,因为在集群环境中管理作业。以下是我使用mysql的jdbc配置:
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName: MyScheduler
org.quartz.scheduler.instanceId: instance_one
org.quartz.scheduler.skipUpdateCheck: true
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 5
org.quartz.threadPool.threadPriority: 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = quartz_cluster
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = true
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.quartz_cluster.driver = com.mysql.cj.jdbc.Driver
org.quartz.dataSource.quartz_cluster.URL = jdbc:mysql://localhost:3306/quartz_cluster
org.quartz.dataSource.quartz_cluster.user = root
org.quartz.dataSource.quartz_cluster.password = root
org.quartz.dataSource.quartz_cluster.maxConnections = 5
Run Code Online (Sandbox Code Playgroud)
每当我运行具有上述属性的夸脱时,我的作业就会开始执行,执行 4 次后,我会收到以下异常:
[ERROR] - [2016-09-15 …
Run Code Online (Sandbox Code Playgroud) 我在 Azure 中有一个定时函数应用程序,计划在每天 22:00 运行。然而,它似乎每天都在 21:59 和 22:00 运行。当我登录 Azure 门户检查日志时,它似乎也是随机运行的。
以下是我收到的重复条目的时间戳示例:
我在网上搜索过但没有找到有效的解决方案。
这是应用程序的签名,大约需要 20 秒才能完成:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 0 22 * * *", RunOnStartup = false)]TimerInfo myTimer, TraceWriter log)
{
// My code
}
Run Code Online (Sandbox Code Playgroud)
这是我的 local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX",
"AzureWebJobsDashboard": "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX",
"type": "timerTrigger",
"schedule": "0 0 22 * * *",
"useMonitor": false,
"SQLConn": "Server=tcp:XXX.database.windows.net,1433;Initial Catalog=XXX;Persist Security Info=False;User ID=XXX;Password=XXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
"disabled": false
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?
此外,Azure 功能中的“监视器”部分也没有显示任何异常。
我希望在声明性管道 jenkins 作业中为每个分支实现不同的 cron 触发器。目前,我只在我们的 dev 分支上触发每小时构建:
String cron_string = BRANCH_NAME == "dev" ? "@hourly" : ""
pipeline {
triggers {
cron(cron_string)
}
//stages, options and more code here...
}
Run Code Online (Sandbox Code Playgroud)
我的目标是拥有两个单独的 cron 字符串,它们将在不同的时间在不同的分支中触发构建(例如:在 dev 中每小时构建一次,在 master 中每三个小时构建一次),但是执行将是相同的。我的问题是,我可以做类似下面的代码块的事情还是应该采取不同的方法?
String cron_string_1 = BRANCH_NAME == "dev" ? "0 8/20 ? * MON-FRY" : ""
String cron_string_2 = BRANCH_NAME == "master" ? "0 8/20/3 ? * MON-FRY" : ""
pipeline {
triggers {
cron(cron_string)
}
//stages, options and more code here...
}
Run Code Online (Sandbox Code Playgroud)