[Spring + quartz] Spring QuartZ timer task of acquiring value Cron

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. QQ discussion groups: 271934368 https://blog.csdn.net/huangjp_hz/article/details/78142042

notes

In doing regular tasks execution price, using Spring QuartZ Cron expression, the time spring-task.xml configuration in the configuration file. In the development of web pages when the need to remove the Cron time to tell the salesperson, the price will be XX of XX, XX XX: XX: XX started.

Cron takes values ​​very simple, CronTriggerImpl methods have encapsulated getNextFireTime () Gets the next execution time can be used DateFormatUtils converted to the desired type, to display the page on OK, the following are examples:

spring-task.xml

<!--配置调价触发的时间-->
<bean id="autoAdjustPriceTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
 <property name="jobDetail" ref="autoAdjustPriceJob" />
 <property name="cronExpression" value="0 20 11 * * ?"></property>
</bean>

AdjustPriceServiceImpl.java


@Autowired
@Qualifier("autoAdjustPriceTriggerBean")    //对应spring-task.xml中的beanId
private org.springframework.scheduling.quartz.CronTriggerFactoryBean autoAdjustPriceTriggerBean;

@Override
public String getNextFireTime() {

    Date date = autoAdjustPriceTriggerBean.getObject().getNextFireTime();
    String nextFireTime = DateFormatUtils.format(date, "HH:mm:ss");

    return nextFireTime;
}

end

Guess you like

Origin blog.csdn.net/huangjp_hz/article/details/78142042
Recommended