Spring4 quartz job xml configuration

2024-02-21 19:38

本文主要是介绍Spring4 quartz job xml configuration,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

 1. 定义job details

public class NotifyJobProcessor extends JobProcessor {private static final Log LOG = LogFactory.getLog(NotifyJobProcessor.class);public NotifyJobProcessor() {}@Overridepublic void execute(JobExecutionContext context) throws JobExecutionException {String jobName = UploadType.NOTIFY.name();LOG.debug("%s Job is running ......", jobName);Channel channel = getChannelFromContext(context);try {if (channel != null && channel.isWritable()) {UploadHeartbeat heartbeat = new UploadHeartbeat(UploadType.NOTIFY);UploadFunction notifyFunction = new UploadFunction(heartbeat);UploadFrame frame = new UploadFrame(notifyFunction);channel.writeAndFlush(frame);return;}}catch (Exception e) {LOG.error("Send %s Message failed !!!", jobName);e.printStackTrace();}LOG.info("Channel is not active or null for %s Job, not need run it any more.", jobName);// channel is not active, then disable triggerdisableTrigger(jobName);}}

 jobprocessor定义:

public abstract class JobProcessor implements Job {private static final Log LOG = LogFactory.getLog(JobProcessor.class);protected Channel getChannelFromContext(JobExecutionContext context) {Channel channel = null;try {Scheduler schedule = context.getScheduler();SchedulerContext scheduleContext = schedule.getContext();channel = (Channel) scheduleContext.get("channel");}catch (SchedulerException e) {LOG.error("get Channel in Job Execution Context failed !!!", e);e.printStackTrace();}return channel;}protected void disableTrigger(String jobName) {try {LOG.info("Going to remove %s Job", jobName);UploadJobManager.getInstance().unTrigger(jobName);}catch (SchedulerException e) {LOG.error("Untrigger %s Job failed !!!", jobName);e.printStackTrace();}}
}

 

 

 2. 配置job details

	<!-- For times when you need more complex processing, passing data to the scheduled job --><bean name="notify.job.processor.detail"  class="org.springframework.scheduling.quartz.JobDetailFactoryBean"><property name="jobClass" value="com.eifesun.monitor.upload.uploader.processor.NotifyJobProcessor" /><property name="durability" value="true" /></bean>

 

 

 3.配置job trigger

  变量

	 <bean id="heartbeatSecond" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"><property name="targetObject" ref="upload.setting"/><property name="targetMethod" value="getSendHeartBeatSecond"/></bean>   

 trigger

	<bean id="notify.job.processor.trigger"  class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"><property name="jobDetail" ref="notify.job.processor.detail" /><property name="startDelay" value="5" /><property name="repeatInterval" value="#{heartbeatSecond}" /></bean>

 

 

 4.配置job scheduler

<bean id="job.processor.scheduler"  class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="autoStartup" value="false"/><property name="jobDetails"><list><ref bean="notify.job.processor.detail" /></list></property><property name="triggers"><list><ref bean="notify.job.processor.trigger" /></list></property></bean> 

 

 

最后,

如果job中有外部依赖,可以这样配置

	<bean name="report.job.processor.detail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"><property name="jobClass"value="com.eifesun.monitor.upload.uploader.processor.ReportJobProcessor" /><property name="jobDataMap"><map><entry key="inverterRepo" value-ref="inverter.repo" /><entry key="deviceRepo" value-ref="device.repo" /></map></property><property name="durability" value="true" /></bean>  

 

 

这篇关于Spring4 quartz job xml configuration的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/732852

相关文章

intellij idea generatorConfig.xml

generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-ge

xml概论

以下内容摘录自W3School 一、XML的特性 xml是用来传输和存储数据的,本身对数据没有任何操作。在这里要区别一下html,html是用来显示数据的。xml的焦点是数据内容,html的焦点是数据外观。 下面是xml的定义: •XML 指可扩展标记语言(EXtensible Markup Language) •XML 是一种标记语言,很类似 HTML

XML的创建

这里使用的是org.dom4j的jar包来完成xml格式数据的创建。 import java.io.IOException;import java.io.StringWriter;import org.dom4j.Document;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.

Spring下自定义xml标签

dubbo自定义了很多xml标签,例如<dubbo:application>,那么这些自定义标签是怎么与spring结合起来的呢?我们先看一个简单的例子。 一 编写模型类 1 package com.hulk.testdubbo.model;2 3 public class Hero {4 private String name;5 private int

xml reader

// TODO Auto-generated method stub

spring事务属性的xml格式配置

实际是使用代理做的事务优化 <!--配置事务的属性--><tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!--匹配所有以add开头的方法--><tx:method name="add*" propagation="REQUIRED" /> <tx:metho

在struts.xml中,如何配置请求转发和请求重定向!

<span style="font-size:18px;"><span style="white-space:pre"> </span><!--<strong>下面用请求转发action </strong>,<strong>这样过去id不会丢</strong>,如果用重定向的话,id会丢 --><result name="updatePopedom"<span style="color:#ff00

xml数据作为表单参数在网络传递也需要用urlencode处理

xml数据作为表单参数在网络传递也需要用urlencode处理。才能确保数据被正确的传递和解析。需要加深对数据在web上传递的理解。

How can I load the openai api configuration through js in html?

题意:怎样在HTML中通过JavaScript加载OpenAI API配置 问题背景: I am trying to send a request through js in my html so that openai analyzes it and sends a response, but if in the js I put the following: 我正在尝试通过HTM