当前位置: 首页 > news >正文

网站开发实训报告模板长春网站建设设计

网站开发实训报告模板,长春网站建设设计,微信小程序成本,专门做零食批发的网站Quartz是实现了序列化接口的,包括接口,所以可以使用标准方式序列化到数据库。 而Spring2.5.6在集成Quartz时却未能考虑持久化问题。 Spring对JobDetail进行了封装,却未实现序列化接口,所以持久化的时候会产生NotSerializable问题&…

Quartz是实现了序列化接口的,包括接口,所以可以使用标准方式序列化到数据库。
而Spring2.5.6在集成Quartz时却未能考虑持久化问题。
Spring对JobDetail进行了封装,却未实现序列化接口,所以持久化的时候会产生NotSerializable问题,这也是网上一直在那边叫嚣为什么不能持久化到数据库问题,哥今天看了下Spring源码,发现Spring对Quartz持久化的问题.
1. 不知道Spring未来会不会对持久化的支持,不过我们可以有如下解决方案,比如改写
Spring的代码,实现序列化接口.
2. 不使用Spring的Fatory,自己实现任务的初始化.

既然Spring不支持持久化,那么持久化任务还是自己编写实现吧,否则每次都需要打包发布,麻烦,自己编写的类与Quartz完全兼容.

注意:为什么Spring不支持外配置任务,可能也是考虑到这方面问题所以才不提供这些任务的执行化支持.[配置文件配置与数据库配置重复]

直接使用Quartz是支持序列化功能,比如直接使用页面配置Quartz界面,设置任务执行时间等属性。

通过配置实现的是不应该初始化到数据库,否则直接在数据库中配置了。不过也是可以配置的,通过改写JobDetailBean.代码如下:

  1. package org.frame.auth.service;  import java.util.Map;  import org.quartz.Job;  
    import org.quartz.JobDetail;  
    import org.quartz.Scheduler;  
    import org.springframework.beans.factory.BeanNameAware;  
    import org.springframework.beans.factory.InitializingBean;  
    import org.springframework.scheduling.quartz.DelegatingJob;  
    import org.springframework.scheduling.quartz.SchedulerFactoryBean;  public class PersistentJobDetailBean extends JobDetail  
    implements BeanNameAware, InitializingBean {  private static final long serialVersionUID = -4389885435844732405L;  private Class actualJobClass;  private String beanName;  /** * Overridden to support any job class, to allow a custom JobFactory * to adapt the given job class to the Quartz Job interface. * @see SchedulerFactoryBean#setJobFactory */  public void setJobClass(Class jobClass) {  if (jobClass != null && !Job.class.isAssignableFrom(jobClass)) {  super.setJobClass(DelegatingJob.class);  this.actualJobClass = jobClass;  }  else {  super.setJobClass(jobClass);  }  }  /** * Overridden to support any job class, to allow a custom JobFactory * to adapt the given job class to the Quartz Job interface. */  public Class getJobClass() {  return (this.actualJobClass != null ? this.actualJobClass : super.getJobClass());  }  /** * Register objects in the JobDataMap via a given Map. * <p>These objects will be available to this Job only, * in contrast to objects in the SchedulerContext. * <p>Note: When using persistent Jobs whose JobDetail will be kept in the * database, do not put Spring-managed beans or an ApplicationContext * reference into the JobDataMap but rather into the SchedulerContext. * @param jobDataAsMap Map with String keys and any objects as values * (for example Spring-managed beans) * @see SchedulerFactoryBean#setSchedulerContextAsMap */  public void setJobDataAsMap(Map jobDataAsMap) {  getJobDataMap().putAll(jobDataAsMap);  }  /** * Set a list of JobListener names for this job, referring to * non-global JobListeners registered with the Scheduler. * <p>A JobListener name always refers to the name returned * by the JobListener implementation. * @see SchedulerFactoryBean#setJobListeners * @see org.quartz.JobListener#getName */  public void setJobListenerNames(String[] names) {  for (int i = 0; i < names.length; i++) {  addJobListener(names[i]);  }  }  public void setBeanName(String beanName) {  this.beanName = beanName;  }  public void afterPropertiesSet() {  if (getName() == null) {  setName(this.beanName);  }  if (getGroup() == null) {  setGroup(Scheduler.DEFAULT_GROUP);  }  }  }  


这里把Spring的ApplicationContext去掉了,因为这个属性没有实现序列化接口。其他配置与原告一致:

  1. <?xml version="1.0" encoding="UTF-8"?>  
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" " http://www.springframework.org/dtd/spring-beans.dtd ">  
    <beans default-autowire="byName">  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">  <property name="driverClassName" value="com.mysql.jdbc.Driver"/>  <property name="url" >  <value><![CDATA[jdbc:mysql://localhost:3306/txl?connectTimeout=1000&useUnicode=true&characterEncoding=utf-8]]></value>  </property>  <property name="username" value="root"/>  <property name="password" value=""/>  </bean>  <bean id="jobDetail" class = "org.frame.auth.service.PersistentJobDetailBean">  <property name="jobClass" value="org.frame.auth.service.PersistentJob"></property>  </bean>  <!-- <bean id="trigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean" >-->  
    <!--         <property name="jobDetail" ref="jobDetail"></property>-->  
    <!--         <property name="startDelay" value="1000"></property>-->  
    <!--         <property name="repeatInterval" value="3000"></property>-->  
    <!--         <property name="jobDataAsMap">-->  
    <!--             <map>-->  
    <!--                 <entry key="message" value="this is trigger"></entry>-->  
    <!--             </map>-->  
    <!--         </property>-->  
    <!-- </bean>-->  <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" >  <property name="jobDetail" ref="jobDetail"/>  <property name="cronExpression">  <value>0/10 * * * * ?</value>  </property>  </bean>  <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  <property name="dataSource" ref="dataSource"></property>  <property name="applicationContextSchedulerContextKey"  value="applicationContextKey" />  <property name="configLocation" value="classpath:quartz.properties"/>  </bean>  </beans>  



org.frame.auth.service.PersistentJob这个类很简单,如下:

  1. package org.frame.auth.service;  import org.quartz.Job;  
    import org.quartz.JobExecutionContext;  
    import org.quartz.JobExecutionException;  public class PersistentJob implements Job  {  @Override  public void execute(JobExecutionContext context) throws JobExecutionException {  System.out.println("spring quartz!");  }  }  



有人可能会说,你这种任务调度持久化就没有意义了,是的,一般持久化到数据库的代码如下:

  1. package org.frame.auth.service;  import java.util.Map;  import org.quartz.JobExecutionContext;  
    import org.quartz.JobExecutionException;  
    import org.quartz.StatefulJob;  public class PersistentJob implements StatefulJob  {  @Override  public void execute(JobExecutionContext context) throws JobExecutionException {  // TODO Auto-generated method stub  Map map = context.getJobDetail().getJobDataMap();  System.out.println("["+context.getJobDetail().getName()+"]"+map.get("message"));  map.put("message", "updated Message");  }  }  


这样的话,信息message就会持久化到数据库中了.可以建立系统的连锁调度,这根据你的业务需求了.

在Spring中配置的任务通过我这种修改是可以运行,不过每次运行都需要把原先的任务删除,否则会提示任务已经存在,Quartz的优势是就算服务器停止,下次重启能够恢复原先的任务并继续执行.


文章转载自:
http://dinncofearnought.ydfr.cn
http://dinncowalkthrough.ydfr.cn
http://dinncoexpurgate.ydfr.cn
http://dinnconato.ydfr.cn
http://dinncoflay.ydfr.cn
http://dinncobaptism.ydfr.cn
http://dinncondola.ydfr.cn
http://dinncochrysotile.ydfr.cn
http://dinncohaploidic.ydfr.cn
http://dinncoholandric.ydfr.cn
http://dinncoapteral.ydfr.cn
http://dinncomastermind.ydfr.cn
http://dinncocheribon.ydfr.cn
http://dinncocragginess.ydfr.cn
http://dinncotchick.ydfr.cn
http://dinncofian.ydfr.cn
http://dinncolustrous.ydfr.cn
http://dinncotroika.ydfr.cn
http://dinncosteadfast.ydfr.cn
http://dinncoaegeus.ydfr.cn
http://dinncogettysburg.ydfr.cn
http://dinncolandscape.ydfr.cn
http://dinncogruyere.ydfr.cn
http://dinncorattailed.ydfr.cn
http://dinncoconfectioner.ydfr.cn
http://dinncoshelf.ydfr.cn
http://dinncospanish.ydfr.cn
http://dinncoforerunner.ydfr.cn
http://dinncocookie.ydfr.cn
http://dinncoyen.ydfr.cn
http://dinncostodginess.ydfr.cn
http://dinncoarkansan.ydfr.cn
http://dinncomesocardium.ydfr.cn
http://dinncoammonotelism.ydfr.cn
http://dinncosyncopation.ydfr.cn
http://dinncoestablishment.ydfr.cn
http://dinncooecumenicity.ydfr.cn
http://dinncoamorphic.ydfr.cn
http://dinncowashcloth.ydfr.cn
http://dinncofleapit.ydfr.cn
http://dinncotibiofibula.ydfr.cn
http://dinncoshoe.ydfr.cn
http://dinncofhwa.ydfr.cn
http://dinncocypress.ydfr.cn
http://dinncomalentendu.ydfr.cn
http://dinncoconversible.ydfr.cn
http://dinncofibrilliform.ydfr.cn
http://dinncoethnopsychology.ydfr.cn
http://dinncoteeter.ydfr.cn
http://dinncosojourn.ydfr.cn
http://dinncoflocculant.ydfr.cn
http://dinncoumbra.ydfr.cn
http://dinncoanachronously.ydfr.cn
http://dinncoflagstaff.ydfr.cn
http://dinncotropism.ydfr.cn
http://dinncotbilisi.ydfr.cn
http://dinncoudt.ydfr.cn
http://dinncosequenator.ydfr.cn
http://dinncoservosystem.ydfr.cn
http://dinncotemporal.ydfr.cn
http://dinncosncf.ydfr.cn
http://dinncoconcolorous.ydfr.cn
http://dinnconebbish.ydfr.cn
http://dinncoreticent.ydfr.cn
http://dinncoviscoelasticity.ydfr.cn
http://dinncodevoir.ydfr.cn
http://dinncofpe.ydfr.cn
http://dinncoinitiate.ydfr.cn
http://dinncokeepsake.ydfr.cn
http://dinncoliberate.ydfr.cn
http://dinncoapparel.ydfr.cn
http://dinncophotog.ydfr.cn
http://dinncocontempt.ydfr.cn
http://dinncophonetics.ydfr.cn
http://dinncomaggotry.ydfr.cn
http://dinncovolant.ydfr.cn
http://dinncohistrionical.ydfr.cn
http://dinncolyssic.ydfr.cn
http://dinncospeechmaker.ydfr.cn
http://dinncoslice.ydfr.cn
http://dinncowhitetail.ydfr.cn
http://dinnconocturnality.ydfr.cn
http://dinncowoodrow.ydfr.cn
http://dinncopodite.ydfr.cn
http://dinncoripsaw.ydfr.cn
http://dinncovaranasi.ydfr.cn
http://dinncozymogenic.ydfr.cn
http://dinncocachepot.ydfr.cn
http://dinncosejant.ydfr.cn
http://dinncooligoclase.ydfr.cn
http://dinncoarcheology.ydfr.cn
http://dinncoroding.ydfr.cn
http://dinncoethnobiology.ydfr.cn
http://dinncoebola.ydfr.cn
http://dinncointermontane.ydfr.cn
http://dinncoaralia.ydfr.cn
http://dinnconaboth.ydfr.cn
http://dinncoonager.ydfr.cn
http://dinncoarchibald.ydfr.cn
http://dinncoferocity.ydfr.cn
http://www.dinnco.com/news/104369.html

相关文章:

  • 佛山网站建设推广订做友情网站
  • 安徽合肥制作网站公司百度竞价优化软件
  • 网站如何引导网站推广网站
  • 单位建设网站注意点拉新推广怎么做代理
  • 方庄网站建设网络营销方案策划书
  • 网站打不开被拦截怎么办免费建站网站
  • 可以在线做试卷的网站郭生b如何优化网站
  • 网站开发后台用什么seo网站推广招聘
  • 网站名称没有排名湖南长沙seo
  • 重庆网站建设加q.479185700免费网页制作模板
  • 东莞seo网络营销策划成都官网seo服务
  • 做肥料网站百度网页链接
  • 独立商城系统网站建设学it一年的学费大概是多少
  • 扬州哪里做网站长沙网络营销公司排名
  • 郑州网站设计制作哪家好互联网推广怎么找渠道
  • 阜新百姓网免费发布信息seo网站营销推广
  • 做网站能拿多少钱天津搜索引擎优化
  • 用百度网盘做视频网站星巴克seo网络推广
  • 网站建设哪里有搜索引擎优化专员
  • 网站无法添加图片自动引流推广软件
  • 校园网站建设的要素网站关键词怎么优化排名
  • 专做女装拿货的网站搜索引擎优化seo应用
  • 网站建设公司 佛山查网站流量查询工具
  • 品牌网站建设公司有哪些东莞关键词优化实力乐云seo
  • 福建省住房和城乡建设网站最简单的网页制作
  • 衢州 网站建设广州seo网络培训课程
  • 罗湖做网站联系电话宁波网站建设公司哪家好
  • 南通网站建设设计百度首页排名优化公司
  • 东阳建设局网站营销软文300字
  • 个人备案用作资讯网站网络seo首页