Quartz -JOB类型 与 动态设定Trigger参数

论坛 期权论坛     
选择匿名的用户   2021-6-2 16:46   328   0
<h1 style="margin:0px; padding:0px; font-family:Arial; line-height:26px; text-align:left"> <span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">一 JOB State</span></h1>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left"> 在通过<span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">MethodInvokingJobDetailFactoryBean在运行中动态生成的Job,配置的xml文件有个concurrent属性,表示job是否可以并行运行:如果一个job的业务处理发费的时间超过了job的启动的间隔时间(repeatInterval),这个属性非常有用。如果为false,那么,在这种情况下,当前job还在运行,那么下一个job只能延时运行。如果为true,那么job就会并行运行。在实际的应用中应该配置为true/false,要根据需要了(废话)。</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left">  </p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left"> <span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">如果通过继承QuartzJobBean实现job的话,默认情况下QuartzJobBean是implements org.quartz.Job接口的,也就是说job示例是stateless的,会出现前面所述的并行情况。而代码中却要求job任务必需串行,解决办法:在job子类中继续implements org.quartz.StatefulJob。那么这个job实例变成了Stateful,job任务也就是串行的了。</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left">  </p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left">  </p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left"> <span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">注:</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left"> <span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">在Quartz中,如果实现org.quartz.Job接口,那么这个job是stateless的,job实例的参数不能在多个任务之间共享,如果实现org.quartz.StatefulJob,这个job是个单例的,job实例的属性可以从当前任务传递到下一个任务。</span></p>
<p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; font-family:Arial; font-size:14px; line-height:26px; text-align:left">  </p>
<h1 style="margin:0px; padding:0px; font-family:Arial; line-height:26px; text-align:left"> <span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)">二 动态设定Trigger参数</span></h1>
<div>
<span lang="EN-US" style="font-size:10pt; font-family:宋体; color:rgb(48,48,48)"></span>
<div class="tit" style="font-family:Arial; word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; font-size:14px; line-height:18px; font-weight:bold; overflow:hidden">
  <br>
</div>
<table style="table-layout:fixed; font-family:Arial; width:960px"><tbody><tr><td style="font-family:Arial; word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; line-height:18px">
     <div class="cnt" id="blog_text" style="word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; font-size:14px; line-height:20px; color:rgb(51,51,51); overflow:hidden; position:relative!important">
      <div style="word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; line-height:normal">
       <span style="font-size:12px">什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什么任务,但任务的定时是不确定的(是由客户制定)。</span>
      </div>
      <div style="word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; line-height:normal">
       <span style="font-size:12px">这样总不能修改配置文件每定制个定时任务就增加一个trigger吧,即便允许客户修改配置文件,但总需要重新启动web服务啊,研究了下Quartz在Spring中的动态定时,发现&lt;bean id&#61;&#34;cronTrigger&#34; class&#61;&#34;org.springframework.scheduling.quartz.CronTriggerBean&#34; &gt;</span>
      </div>
      <div style="word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; line-height:normal">
       <span style="font-size:12px">          &lt;property name&#61;&#34;jobDetail&#34; ref&#61;&#34;schedulerJobDetail&#34;/&gt;</span>
      </div>
      <div style="word-wrap:break-word; word-break:break-all; visibility:visible!important; zoom:1!important; line-height:normal">
       <span style="font-si
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP