??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品一二三视频,极品美乳网红视频免费在线观看,欧美91在线|欧美http://www.aygfsteel.com/stevenjohn/category/52416.html那些青春的岁?/description>zh-cnSun, 26 Jul 2015 19:18:47 GMTSun, 26 Jul 2015 19:18:47 GMT60Quartz q发http://www.aygfsteel.com/stevenjohn/archive/2015/07/26/426425.htmlabinabinSat, 25 Jul 2015 17:39:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2015/07/26/426425.htmlhttp://www.aygfsteel.com/stevenjohn/comments/426425.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2015/07/26/426425.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/426425.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/426425.html1?/span>StatefulJob
implements StatefulJob使Job成ؓ有状态的Q顺序执?nbsp;
同一个有状态的job实例不存在ƈ发,无状态的job的ƈ发数׃面配|的U程数决定。不惛_ƈ发的话,讄?Q第二个U程在前一个执行完以后触发执行?/span>
U程数大?Ӟ如果存在I闲U程Q则到执行时间点卌发执行?/span>

2?/span>MethodInvokingJobDetailFactoryBean
MethodInvokingJobDetailFactoryBean的ƈ发问?/div>
大家在用quartz的时候,一般只讄?#8220;targetObject”?#8220;targetMethod”QMethodInvokingJobDetailFactoryBeanc默认是q发执行的,q时候如果不讄“concurrent”为falseQ很可能带来q发或者死锁的问题Q而且几率较小Q不Ҏ复现Q请大家使用的时候注意设|?#8220;concurrent”?/div>
 
    <bean id="cpm.MessageJobFactoryBean" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="cpm.MessageJob"/>
        <property name="targetMethod" value="execute"/>
        <property name="concurrent" value="false"/>
    </bean>
concurrent   同时发生
 concurrentQ对于相同的JobDetailQ当指定多个Trigger? 很可能第一个job完成之前Q第二个job开始了?/div>
 定concurrent设ؓfalseQ多个job不会q发q行Q第二个job不会在W一个job完成之前开?/div>



防止jobq行q行的几U解x?nbsp;
一、JOB State 
在通过MethodInvokingJobDetailFactoryBean在运行中动态生成的JobQ配|的xml文g有个concurrent属性,表示job是否可以q行q行Q如果一个job的业务处理发费的旉过了job的启动的间隔旉QrepeatInterval)Q这个属性非常有用。如果ؓfalseQ那么,在这U情况下Q当前jobq在q行Q那么下一个job只能延时q行。如果ؓtrueQ那么job׃q行q行。在实际的应用中应该配置为true/falseQ要Ҏ需要了Q废话)?nbsp;
二、如果通过l承QuartzJobBean实现job的话Q默认情况下QuartzJobBean是implements org.quartz.Job接口的,也就是说jobCZ是stateless的,会出现前面所q的q行情况。而代码中却要求jobd必需串行Q解军_法:在job子类中limplements org.quartz.StatefulJob。那么这个job实例变成了StatefulQjobd也就是串行的了?/div>
注: 
在Quartz中,如果实现org.quartz.Job接口Q那么这个job是stateless的,job实例的参C能在多个d之间׃nQ如果实现org.quartz.StatefulJobQ这个job是个单例的,job实例的属性可以从当前d传递到下一个Q务?nbsp;


spring和quartz的整合对版本是有要求的?/div>
spring3.1以下的版本必M用quartz1.xpdQ?.1以上的版本才支持quartz 2.xQ不然会出错?/div>
至于原因Q则是spring对于quartz的支持实玎ͼorg.springframework.scheduling.quartz.CronTriggerBeanl承了org.quartz.CronTriggerQ在quartz1.xpd中org.quartz.CronTrigger是个c,而在quartz2.xpd中org.quartz.CronTrigger变成了接口,从而造成无法用spring的方式配|quartz的触发器QtriggerQ?br />
在Spring中用Quartz有两U方式实玎ͼW一U是dcȝ承QuartzJobBeanQ第二种则是在配|文仉定义dcd要执行的ҎQ类和方法可以是普通类。很昄Q第二种方式q比W一U方式来的灵zR?/div>


MethodInvokingJobDetailFactoryBean中concurrent和shouldRecover属性的作用
解释 concurrent为trueQ则允许一个QuartzJobq发执行Q否则就是顺序执行。例如QuartzJob A执行旉?5U,配置为每10U执行一ơ;如果concurrent为trueQ则0U的时候启动一ơAQ?0U的时候再启动一ơAQ?0U的时候再启动一ơAQ不前面启动的A有没有执行完Q如果concurrent为falseQ则0U的时候启动一ơAQ?5U的时候A执行完毕Q再W二ơ启动A?
shouldRecover属性ؓtrueQ则当Quartz服务被中止后Q再ơ启动或集群中其他机器接手Q务时会尝试恢复执行之前未完成的所有Q务。例如QuartzJob BQ在每次00U的时候启动,假如?3:00的Q务执行完之后服务?被中止,服务??5:15的时候才接手Q如果shouldRecover属性ؓtrueQ则服务?会尝试着补回原来?4:00?5:00的时候应该做的Q务,如果shouldRecover属性ؓfalseQ则服务?只会?6:00的时候再执行B?br />

Quartz集群只支持JDBCJobStore存储方式Q而MethodInvokingJobDetailFactoryBean不能序列化存储job数据到数据库Q?/pre>
重写 quartz ?QuartzJobBean c?nbsp;
原因是在使用 quartz+spring ?quartz ?task 实例化进入数据库Ӟ会生: serializable 的错误,原因在于Q?/div>
q个 MethodInvokingJobDetailFactoryBean cM?methodInvoking ҎQ是不支持序列化的,因此在把 QUARTZ ?TASK 序列化进入数据库时就会抛错。网上有说把 SPRING 源码拿来Q修改一下这个方案,然后再打包成 SPRING.jar 发布Q这些都是不好的ҎQ是不安全的?/div>
必须Ҏ QuartzJobBean 来重写一个自qc??/div>




abin 2015-07-26 01:39 发表评论
]]>quartz 数据?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2015/07/23/426393.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Thu, 23 Jul 2015 07:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2015/07/23/426393.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/426393.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2015/07/23/426393.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/426393.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/426393.html</trackback:ping><description><![CDATA[<span style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_CALENDARS ?Blob cd存储 Quartz ?Calendar ?/span><span style="color: #464646; font-family: simsun; background-color: #dcdcdc;">?nbsp;</span><wbr style="color: #464646; font-family: simsun; background-color: #dcdcdc;"><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_CRON_TRIGGERS 存储 Cron TriggerQ包?Cron表达式和时区信息 <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_FIRED_TRIGGERS 存储与已触发?Trigger 相关的状态信息,以及相联 Job的执行信息QRTZ_PAUSED_TRIGGER_GRPS 存储已暂停的 Trigger l的信息 <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_SCHEDULER_STATE 存储量的有?Scheduler 的状态信息,和别?Scheduler实例(假如是用于一个集中) <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_LOCKS 存储E序?span style="word-wrap: normal; word-break: normal;">?/span>观锁的信?假如使用了悲观锁) <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_JOB_DETAILS 存储每一个已配置?Job 的详l信?nbsp;<wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_JOB_LISTENERS 存储有关已配|的 JobListener 的信?nbsp;<wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_SIMPLE_TRIGGERS 存储单的TriggerQ包括重复次敎ͼ间隔Q以及已触的ơ数 <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_BLOG_TRIGGERS Trigger 作ؓ Blob cd存储(用于 Quartz 用户?JDBC创徏他们自己定制?Trigger cdQJobStore q不知道如何存储实例的时? <wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_TRIGGER_LISTENERS 存储已配|的 TriggerListener 的信?nbsp;<wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">QRTZ_TRIGGERS 存储已配|的 Trigger 的信?nbsp;<wbr></div><div style="color: #464646; font-family: simsun; background-color: #dcdcdc;">--------------------------------------------------------------------------------------------------<div></div><div><span style="word-wrap: normal; word-break: normal; line-height: 26px; color: #555b6e; font-family: Arial; font-weight: bold; text-indent: 8px; background-color: #ffffff;">quartz 持久化数据库表格字段解释</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">,SQL语句在quartz-1.6.6\docs\dbTables文g夹中可以扑ֈ,介绍下主要的几张表: <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 表qrtz_job_details: 保存job详细信息,该表需要用h据实际情况初始化 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_name:集群中job的名?该名字用戯己可以随意定?无强行要?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_group:集群中job的所属组的名?该名字用戯己随意定?无强行要?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_class_name:集群中个note job实现cȝ完全包名,quartz是Ҏq个路径到classpath扑ֈ该jobc?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> is_durable:是否持久?把该属性设|ؓ1Qquartz会把job持久化到数据库中 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_data:一个blob字段Q存放持久化job对象 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 表qrtz_triggers: 保存trigger信息 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_name: trigger的名?该名字用戯己可以随意定?无强行要?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_group:trigger所属组的名?该名字用戯己随意定?无强行要?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_name: qrtz_job_details表job_name的外?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> job_group: qrtz_job_details表job_group的外?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_state:当前trigger状态,讄为ACQUIRED,如果讄为WAITING,则job不会触发 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_cron:触发器类?使用cron表达?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 表qrtz_cron_triggers:存储cron表达式表 <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_name: qrtz_triggers表trigger_name的外?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> trigger_group: qrtz_triggers表trigger_group的外?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> cron_expression:cron表达?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> 表qrtz_scheduler_state:存储集群中note实例信息Qquartz会定时读取该表的信息判断集群中每个实例的当前状?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> instance_name:之前配置文g中org.quartz.scheduler.instanceId配置的名字,׃写入该字D,如果讄为AUTO,quartz会根据物理机名和当前旉产生一个名?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> last_checkin_time:上次查时?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> checkin_interval:查间隔时?nbsp;<wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><strong style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">步骤4</strong><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">: <wbr></span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"> <wbr>配置quartz.properties文gQ?/span><br style="line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;" /><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#调度标识?集群中每一个实例都必须使用相同的名U?nbsp;org.quartz.scheduler.instanceName = scheduler</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#ID讄动获?每一个必M?nbsp;org.quartz.scheduler.instanceId = AUTO</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#数据保存方式为持久化 org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#数据库^?org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate #数据库别?随便取org.quartz.jobStore.dataSource = myXADS</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#表的前缀 org.quartz.jobStore.tablePrefix = QRTZ_</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#讄为TRUE不会出现序列化非字符串类?BLOB 时生的cȝ本问?org.quartz.jobStore.useProperties = true</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#加入集群 org.quartz.jobStore.isClustered = true</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#调度实例失效的检查时间间?nbsp;org.quartz.jobStore.clusterCheckinInterval = 20000 <wbr></span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#容许的最大作业g长时?nbsp;org.quartz.jobStore.misfireThreshold = 60000</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#ThreadPool 实现的类?org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#U程数量 org.quartz.threadPool.threadCount = 10</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#U程优先U?org.quartz.threadPool.threadPriority = 5</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#自创建父U程 org.quartz.threadPool.threadsInheritContextCla<wbr>ssLoaderOfInitializingTh<wbr>read = true <wbr></span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#讄数据源org.quartz.dataSource.myXADS.jndiURL = CT</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">#jbdicd org.quartz.dataSource.myXADS.java.naming.factory.initial = weblogic.jndi.WLInitialContextFactory #URLorg.quartz.dataSource.myXADS.java.naming.provider.url = t3://localhost:7001</span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;"><br /></span></div><div><span style="word-wrap: normal; word-break: normal; line-height: normal; color: #2a2929; font-family: Arial; font-size: 12px; background-color: #ffffff;">【注】:在J2EE工程中如果想用数据库理Quartz的相关信息,׃定要配置数据源,q是Quartz的要求?/span></div></div><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/426393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2015-07-23 15:31 <a href="http://www.aygfsteel.com/stevenjohn/archive/2015/07/23/426393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>U代码实现Quartz定时??http://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386255.htmlabinabinSat, 25 Aug 2012 04:43:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386255.htmlhttp://www.aygfsteel.com/stevenjohn/comments/386255.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386255.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/386255.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/386255.htmlpackage com.abin.lee.quartz.all;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class UniversalQuartz implements Job{

 public void execute(JobExecutionContext arg0) throws JobExecutionException {
  System.out.println("执行定时d: "+System.currentTimeMillis());
  
 }
 
}




package com.abin.lee.quartz.all;

import java.text.ParseException;
import java.util.Date;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;

public class UniversalQuartzManager {
 private static UniversalQuartzManager instance = null;
 private Scheduler sched = null;
 private SchedulerFactory factory = null;

 private UniversalQuartzManager() {
  _init();
 }

 private void _init() {
  factory = new org.quartz.impl.StdSchedulerFactory();
  try {
   sched = factory.getScheduler();
  } catch (SchedulerException e) {
   e.printStackTrace();
  }
 }

 public synchronized static UniversalQuartzManager getInstance() {
  if (instance == null) {
   instance = new UniversalQuartzManager();
  }
  return instance;
 }

 public void start() {
  try {
   sched.start();
   // 在这里加载需要执行的业务逻辑cUniversalQuartz.class
   JobDetail detail = new JobDetail("cmhksynchron", "cmhkSynch",
     UniversalQuartz.class);
   CronTrigger trigger = new CronTrigger();
   // 手动d了时?br />   trigger.setCronExpression("0/10 * * * * ? *");
//   trigger.setCronExpression("0 0-59 16 * * ?");
   trigger.setName("abintrigger");
   trigger.setStartTime(new Date());
   sched.scheduleJob(detail, trigger);
  } catch (SchedulerException e) {
   e.printStackTrace();
  } catch (ParseException e2) {
   e2.printStackTrace();
  }
 }

 public void stop() {
  try {
   sched.shutdown();
   sched = factory.getScheduler();
  } catch (SchedulerException e) {
   e.printStackTrace();
  }
 }

 public void refresh() {
  // 未知的原因,E序执行q段判断q入stopQ)Q在sched.shutdown();q一句报错,//所以暂时将其屏蔽,以待后来解决
  // try {
  // if(sched != null && sched.isStarted()) {
  // this.stop();
  // }
  this.start();
  // } catch (SchedulerException e) {
  // e.printStackTrace();
  // }
 }

}

 




package com.abinl.lee.quartz.all.test;

import com.abin.lee.quartz.all.UniversalQuartzManager;

public class TestQuartz {
 public static void main(String[] args) {
  UniversalQuartzManager.getInstance().refresh(); 
 }

}





abin 2012-08-25 12:43 发表评论
]]>
U代码实现Quartz定时?一)http://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386253.htmlabinabinSat, 25 Aug 2012 03:48:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386253.htmlhttp://www.aygfsteel.com/stevenjohn/comments/386253.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/25/386253.html#Feedback1http://www.aygfsteel.com/stevenjohn/comments/commentRss/386253.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/386253.html

深入解读Quartz的原?br /> 
Quartz是一个大名鼎鼎的Java版开源定时调度器Q功能强悍,使用方便?br /> 
一、核心概?br /> 
Quartz的原理不是很复杂Q只要搞明白几个概念Q然后知道如何去启动和关闭一个调度程序即可?br /> 
1、Job
表示一个工作,要执行的具体内容。此接口中只有一个方?br />void execute(JobExecutionContext context)
 
2、JobDetail
JobDetail表示一个具体的可执行的调度E序QJob是这个可执行E调度程序所要执行的内容Q另外JobDetailq包含了q个d调度的方案和{略?/p>

 
3、Trigger代表一个调度参数的配置Q什么时候去调?br /> 
4、Scheduler代表一个调度容器,一个调度容器中可以注册多个JobDetail和Trigger。当Trigger与JobDetaill合Q就可以被Scheduler容器调度了?br /> 
 
二、一个最单入门实?br /> 
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
* quartz定时器测?
*
* @author leizhimin 2009-7-23 8:49:01
*/
public class MyJob implements Job {
        public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
                System.out.println(new Date() + ": doing something...");
        }
}

class Test {
        public static void main(String[] args) {
                //1、创建JobDetial对象
                JobDetail jobDetail = new JobDetail();
                //讄工作?
                jobDetail.setJobClass(MyJob.class);
                jobDetail.setName("MyJob_1");
                jobDetail.setGroup("JobGroup_1");

                //2、创建Trigger对象
                SimpleTrigger strigger = new SimpleTrigger();
                strigger.setName("Trigger_1");
                strigger.setGroup("Trigger_Group_1");
                strigger.setStartTime(new Date());
                //讄重复停止旉Qƈ销毁该Trigger对象
                java.util.Calendar c = java.util.Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis() + 1000 * 1L);
                strigger.setEndTime(c.getTime());
                strigger.setFireInstanceId("Trigger_1_id_001");
                //讄重复间隔旉
                strigger.setRepeatInterval(1000 * 1L);
                //讄重复执行ơ数
                strigger.setRepeatCount(3);

                //3、创建Scheduler对象Qƈ配置JobDetail和Trigger对象
                SchedulerFactory sf = new StdSchedulerFactory();
                Scheduler scheduler = null;
                try {
                        scheduler = sf.getScheduler();
                        scheduler.scheduleJob(jobDetail, strigger);
                        //4、ƈ执行启动、关闭等操作
                        scheduler.start();

                } catch (SchedulerException e) {
                        e.printStackTrace();
                }
//                try {
//                        //关闭调度?
//                        scheduler.shutdown(true);
//                } catch (SchedulerException e) {
//                        e.printStackTrace();
//                }
        }
}
 
执行l果Q?/p>

 
当把l束旉改ؓQ?br />                //讄重复停止旉Qƈ销毁该Trigger对象
                java.util.Calendar c = java.util.Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis() + 1000 * 1L);
                strigger.setEndTime(c.getTime());
 
执行l果Q?br /> 
当添加一条关闭调度器的语句:
                        //4、ƈ执行启动、关闭等操作
                        scheduler.start();
                        scheduler.shutdown(true);

 
E序执行l果Q?br />Thu Jul 23 10:11:50 CST 2009: doing something...

Process finished with exit code 0
仅仅执行了一ơ,q一ơ能执行完,原因是设定了scheduler.shutdown(true);true表示{待本次d执行完成后停止?br /> 
从这里也可以看出Qscheduler是个容器Qscheduler控制jobDetail的执行,控制的策略是通过trigger?br /> 
当scheduler容器启动后,jobDetail才能Ҏ兌的trigger{略L行。当scheduler容器关闭后,所有的jobDetail都停止执行?br /> 
三、透过实例看原?br /> 
通过研读Quartz的源代码Q和本实例,l于悟出了Quartz的工作原理?br /> 
1、scheduler是一个计划调度器容器Q总部Q,容器里面可以盛放众多的JobDetail和triggerQ当容器启动后,里面的每个JobDetail都会Ҏtrigger按部q自动L行?br /> 
2、JobDetail是一个可执行的工作,它本w可能是有状态的?br /> 
3、Trigger代表一个调度参数的配置Q什么时候去调?br /> 
4、当JobDetail和Trigger在scheduler容器上注册后QŞ成了装配好的作业QJobDetail和Trigger所l成的一对儿Q,可以伴随容器启动而调度执行了?br /> 
5、scheduler是个容器Q容器中有一个线E池Q用来ƈ行调度执行每个作业,q样可以提高容器效率?br /> 
6、将上述的结构用一个图来表C,如下Q?br /> 

 
四、ȝ
 
1、搞清楚了上Quartz容器执行作业的的原理和过E,以及作业形成的方式,作业注册到容器的Ҏ。就认识明白了Quartz的核心原理?br /> 
2、Quartz虽然很庞大,但是一切都围绕q个核心转,Z配置强大旉调度{略Q可以研I专门的CronTrigger。要想灵z配|作业和容器属性,可以通过Quartz的properties文g或者XML来实现?br /> 
3、要惌度更多的持久化、结构化作业Q可以通过数据库读取作业,然后攑ֈ容器中执行?br /> 
4、所有的一切都围绕q个核心原理转,搞明白这个了Q再ȝI更高用法容易多了?br /> 
5、Quartz与Spring的整合也非常单,Spring提供一lBean来支持:MethodInvokingJobDetailFactoryBean、SimpleTriggerBean、SchedulerFactoryBeanQ看看里面需要注入什么属性即可明白了。Spring会在Spring容器启动时候,启动Quartz容器?br /> 
6、Quartz容器的关闭方式也很简单,如果是Spring整合Q则有两U方法,一U是关闭Spring容器Q一U是获取到SchedulerFactoryBean实例Q然后调用一个shutdown搞定了。如果是Quartz独立使用Q则直接调用scheduler.shutdown(true);
 
7、Quartz的JobDetail、Trigger都可以在q行旉新设|,q且在下ơ调用时候v作用。这׃ؓ动态作业的实现提供了依据。你可以调度时间策略存攑ֈ数据库,然后通过数据库数据来讑֮TriggerQ这样就能生动态的调度?br />


http://blog.csdn.net/jiangfeng861016/article/details/5970745






abin 2012-08-25 11:48 发表评论
]]>Spring Quartz集群http://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385702.htmlabinabinFri, 17 Aug 2012 10:01:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385702.htmlhttp://www.aygfsteel.com/stevenjohn/comments/385702.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385702.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/385702.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/385702.html

Spring+Quartz的集配|?/h2> 
http://blog.sina.com.cn/s/blog_4b0210750100z6jb.html#SinaEditor_Temp_FontName

abin 2012-08-17 18:01 发表评论
]]>Quartz官网 http://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385667.htmlabinabinFri, 17 Aug 2012 03:14:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385667.htmlhttp://www.aygfsteel.com/stevenjohn/comments/385667.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/17/385667.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/385667.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/385667.html官网Qhttp://quartz-scheduler.org/

学习文档Qhttp://quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/

例子Qhttp://quartz-scheduler.org/documentation/quartz-2.1.x/examples/ 

spring集成官网Q?a >http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html#scheduling-quartz



http://blog.csdn.net/lan861698789/article/details/7620104

abin 2012-08-17 11:14 发表评论
]]>
վ֩ģ壺 ҽ| | ƽ| | ƽɽ| ̨| տ| | ɽ| | | ʯɽ| ӥ̶| DZ| | | | | ʼ| ߶| | | | | ɽ| ĺ| | Ϸ| ²| | | | | | Т| | | | | º| |