我想知道是否有一个函数/方法可以创建在随机时间触发的作业。我的意思是,如果我设置一个 cron 计划在每周一上午 10 点触发并给定一个时间间隔(假设为 30 分钟),则触发器将始终从 9.30 ~ 10.30 触发。例如,这是 cron 计划。
schedule.setCronSchedule("0 0 10 ? * MON");
trigger = newTrigger()
.withIdentity(triggerId)
.startNow() // <~~~~~~~~~~~~~~~ ???
.withDescription(schedule.getCronSchedule())
.withSchedule(cronSchedule(schedule.getCronSchedule())).build();
Run Code Online (Sandbox Code Playgroud)
如果我有一个以分钟为单位的特定范围的变量,我可以将其设置为随机触发吗?我的意思是,不仅仅是获取 cron 计划字符串并重新修改它,而是使用一种方法每次触发事件,基于随机范围,因此第一个星期一可能在 10.01 触发,第二个星期一可能在 9.46 触发,依此类推。
提前致谢。
我曾经尝试设置一个小程序,使用 Spring 和 Quartz 来安排任务。我遵循了其他一些类似的答案,但没有运气。目前我认为我已经正确配置了所有配置,我没有看到更多异常,但我的工作看起来还没有开始。
在 Spring 生成的 log.out 中,我在末尾看到以下消息:
2015-06-04T15:46:57.928调试[org.springframework.core.env.PropertySourcesPropertyResolver]在[systemProperties]中搜索键“spring.liveBeansView.mbeanDomain”2015-06-04T15:46:57.929调试[org.springframework。 core.env.PropertySourcesPropertyResolver] 在 [systemEnvironment] 2015-06-04T15:46:57.929 DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] 中搜索键“spring.liveBeansView.mbeanDomain”,找不到键“spring.liveBeansView”。任何属性源中的 mbeanDomain'。返回[空]
我会告诉你我的代码...
这是我启动调度程序的类:
public class JobRunner {
public static void main(String[] args) throws SchedulerException {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(WhatsTheTimeConfiguration.class);
AutowiringSpringBeanJobFactory autowiringSpringBeanJobFactory = new AutowiringSpringBeanJobFactory();
autowiringSpringBeanJobFactory.setApplicationContext(applicationContext);
SpringBeanJobFactory springBeanJobFactory = new SpringBeanJobFactory();
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setTriggers(trigger());
schedulerFactoryBean.setJobFactory(springBeanJobFactory);
schedulerFactoryBean.start();
}
private static SimpleTrigger trigger() {
return newTrigger()
.withIdentity("whatsTheTimeJobTrigger", "jobsGroup1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(1)
.repeatForever())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我想提一下,如果我使用 SchedulerFactoryBean.getScheduler().start() 方法,它会在调度程序上引发空指针异常,这就是为什么我在工厂上调用 start() 的原因。
AutowiringSpringBeanJobFactory …
得到这些错误:
2018-01-22 18:00:59,797 [ServerService Thread Pool -- 79] ERROR org.quartz.ee.servlet.QuartzInitializerListener - Quartz Scheduler failed to initialize: org.quartz.SchedulerException: SchedulerPlugin class 'org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin' could not be instantiated. [See nested exception: java.lang.ClassNotFoundException: Unable to load class org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin by any known loaders.]
2018-01-22 18:00:59,797 [ServerService Thread Pool -- 79] ERROR stderr - org.quartz.SchedulerException: SchedulerPlugin class 'org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin' could not be instantiated. [See nested exception: java.lang.ClassNotFoundException: Unable to load class org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin by any known loaders.]
2018-01-22 18:00:59,805 [ServerService Thread Pool -- 79] ERROR stderr - Caused by: …Run Code Online (Sandbox Code Playgroud) 我试图了解在 Kotlin 中以预定速率触发异步作业的最佳方式是什么,而应用程序通常正在运行它的正常任务。假设我有一个简单的应用程序,它每秒只打印出“...”,但每 5 秒我想要另一个作业/线程/协程(哪个最适合)来打印“你有一条消息!”。对于异步作业,我有一个类NotificationProducer,它看起来像这样。
class NotificationProducer {
fun produce() {
println("You have a message!")
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我的主要方法看起来像这样。
while (true) {
println("...")
sleep(1000)
}
Run Code Online (Sandbox Code Playgroud)
我应该使用GlobalScope.async,Timer().schedule(...)还是一些 Quartz 工作来实现我想要的?任何建议都非常感谢。关键是通知必须来自另一个类(例如 NotificationProducer)
我想使用 jdbc 数据存储立即使用石英调度程序执行作业。但是,即使我使用 now() 或调用 triggerJob 进行调度,我在调度和触发触发之间也有 20-30 秒的延迟。
我试图用一个简单的触发器来执行这项工作:
JobKey key = //...
JobDetail jobDetail = newJob(jobBean.getClass())
.withIdentity(key)
.usingJobData(new JobDataMap(jobParams))
.storeDurably()
.build();
Trigger trigger = newTrigger()
.withIdentity(key.getName(), key.getGroup())
.startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withMisfireHandlingInstructionFireNow()
.withRepeatCount(0))
.build();
scheduler.scheduleJob(jobDetail, trigger);
Run Code Online (Sandbox Code Playgroud)
而且我还尝试使用调度程序触发:
JobKey key = // ...
JobDetail jobDetail = newJob(jobBean.getClass())
.withIdentity(key)
.storeDurably()
.build();
scheduler.addJob(jobDetail, true);
scheduler.triggerJob(key, new JobDataMap(jobParams));
Run Code Online (Sandbox Code Playgroud)
以下是显示延迟的侦听器日志。
2019-05-15 13:59:52,066Z INFO [nio-8081-exec-2] c.m.f.s.logger.SchedulingListener : Job added: newsJobTemplate:1557928791965
2019-05-15 13:59:52,066Z INFO [nio-8081-exec-2] c.m.f.s.logger.SchedulingListener : Job scheduled: newsJobTemplate:1557928791965
2019-05-15 14:00:18,660Z INFO [eduler_Worker-1] c.m.f.s.logger.TriggerStateListener : Trigger …Run Code Online (Sandbox Code Playgroud) 我有一个Quartz用于安排任务的 Windows 服务。而且我试图在Dependency Injection默认情况下实现asQuartz不支持 default Job Factory。所以我必须创建一个自定义Job Factory如下。
var scheduler = await GetScheduler();
var serviceProvider = GetConfiguredServiceProvider();
scheduler.JobFactory = new CustomJobFactory(serviceProvider);
Run Code Online (Sandbox Code Playgroud)
下面是我的代码GetConfiguredServiceProvider()。
private IServiceProvider GetConfiguredServiceProvider() {
var services = new ServiceCollection()
.AddScoped<IDailyJob, DailyJob>()
.AddScoped<IWeeklyJob, WeeklyJob>()
.AddScoped<IMonthlyJob, MonthlyJob>()
.AddScoped<IHelperService, HelperService>();
return services.BuildServiceProvider();
}
Run Code Online (Sandbox Code Playgroud)
但在线上.AddScoped<IDailyJob, DailyJob>()我收到一个错误
严重性代码说明项目文件行抑制状态错误 CS1061“ServiceCollection”不包含“AddScoped”的定义,并且找不到接受“ServiceCollection”类型的第一个参数的可访问扩展方法“AddScoped”(您是否缺少 using 指令或汇编参考?)
还有其他人遇到过同样的问题吗?
c# windows-services dependency-injection quartz-scheduler service-provider
我正在尝试在 Quartz 1.6 中创建一个Job,但只需要执行一次,因为我有两个测试实例,它们具有相同版本的 .war 文件。
这是我的TestPlugin类,Job每 60 秒执行一次:
public class TestPlugin implements PlugIn {
public TestPlugin() {
super();
}
public void destroy() {
}
public void init(ActionServlet arg0, ModuleConfig arg1)
throws ServletException {
try {
JobDetail job = JobBuilder.newJob(TestDemonio.class)
.withIdentity("anyJobName", "group1").build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("anyTriggerName", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0/60 * * ? * * *"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.scheduleJob(job, trigger);
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我是石英新手。我无法在quartz-2.3.0-distribution.tar.gz 的 docs 文件夹下找到数据库脚本。docs 文件夹下只有图像。但它可以在quartz-2.2.3-distribution.tar.gz版本的docs文件夹下找到。在哪里可以找到 2.3.0 版本的数据库脚本?应该和2.2.3版本一样使用吗?另外在哪里可以找到迁移数据库脚本。请帮忙。官方链接http://www.quartz-scheduler.org/documentation/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore正在维护(返工正在进行中)。请帮忙。
有一个奇怪的情况.我在我的企业应用程序中使用Glassfish服务器.在那个应用程序中,我使用的是JSF,Richfaces,Quartz,Jasper Reports和Commons Email.当我构建并部署应用程序到我的开发.计算机,开发和测试服务器,一切正常.但是,当我使用相同的glassfish将应用程序部署到生产服务器时,我无法运行Quartz调度程序.它让我觉得公共收藏有一些问题.我知道某处有冲突,但我无法找到.你能给我一些指点吗?顺便说一下,我正在使用NetBeans 6.5.
这是日志:
[#|2009-02-13T02:00:03.055+0000|WARNING|sun-appserver9.1|javax.enterprise.resource.webcontainer.jsf.lifecycle|_ThreadID=22;_ThreadName=httpSSLWorkerThread-80-4;_RequestID=97d21f45-2489-486c-b8d9-68625776c546;|#{SchedulerController.play}: java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet(Ljava/util/Set;)Ljava/util/Set;
javax.faces.FacesException: #{SchedulerController.play}: java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet(Ljava/util/Set;)Ljava/util/Set;
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107)
at javax.faces.component.UICommand.broadcast(UICommand.java:383)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:288)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571) …Run Code Online (Sandbox Code Playgroud) quartz-scheduler ×10
java ×6
quartz ×2
asynchronous ×1
c# ×1
cron ×1
kotlin ×1
kubernetes ×1
spring ×1
spring-boot ×1