繁体   English   中英

Spring Batch Scheduler:计时器实现

[英]Spring Batch Scheduler : Timer implementation

我必须构建一个在线考试模块,该模块将提供10分钟的考试时间。为实现计时器部分,我当时想与Spring Batch Scheduler一起使用。请参阅以下配置文件:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<context:component-scan base-package="mypackage" />

<bean id="timerService" class="mypackage.TimerService" />


<task:scheduler id="timerScheduler" pool-size="10" />

  <task:scheduled-tasks scheduler="timerScheduler">
     <task:scheduled ref="timerService" method="displayTimer"
         fixed-rate="1000" />
  </task:scheduled-tasks>
</beans>

在调用期间,我从一个主要方法调用:

ClassPathXmlApplicationContext context = new 
ClassPathXmlApplicationContext("spring/applicationContext.xml");

一切都很好,除了计时器会在容器加载后立即启动。 但是我的目标是在用户开始检查后立即启动计划程序(例如,在方法调用/按钮单击之后),而不是在应用程序启动时开始。

任何人都可以在配置中提供任何线索来实现这种情况。 我知道trigger属性,但是它通常与cron表达式一起使用,在我的情况下,触发器不会基于时间,而是基于事件。 所以,我不能通过cron。

谁能为此提供任何合适的解决方案? 只有我将自己实现一个如何基于特定方法调用rest调用调度程序的方法。

Spring batch scheduler没有这样的东西,您指的是Spring Framework的任务调度。

计划与您的“例如:方法调用/按钮单击后”的要求不兼容。 计划意味着要事先知道计划,但是在您的情况下,您并不知道用户何时单击按钮。 您实际需要的是根据用户操作启动倒数计时器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM