[英]Spring Batch Scheduler : Timer implementation
I have to build a online exam module which will be providing 10 minutes duration for exam completion.For implementing the timer part I was thinking to go with Spring batch scheduler.Refer to below config file: 我必须构建一个在线考试模块,该模块将提供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>
During invocation I am invoking from a main method: 在调用期间,我从一个主要方法调用:
ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext("spring/applicationContext.xml");
Everything is fine except,timer will be strted as soon as the container is loaded. 一切都很好,除了计时器会在容器加载后立即启动。 But my aim is to start the scheduler as soon as user start the exam[eg:after a method invocation/button click] and not on application startup. 但是我的目标是在用户开始检查后立即启动计划程序(例如,在方法调用/按钮单击之后),而不是在应用程序启动时开始。
Can anyone provide any clue in configuration for implementing such scenario. 任何人都可以在配置中提供任何线索来实现这种情况。 I know about trigger
attribute but it generally works with cron expression and in my case trigger won't be based on time rather based on an event. 我知道trigger
属性,但是它通常与cron表达式一起使用,在我的情况下,触发器不会基于时间,而是基于事件。 so,I cann't go via cron. 所以,我不能通过cron。
Can anyone provide any suitable solution to this? 谁能为此提供任何合适的解决方案? only how to invoke the scheduler based on a particualar method call rest I will implement by myself. 只有我将自己实现一个如何基于特定方法调用rest调用调度程序的方法。
There is no such thing Spring batch scheduler
, you are referring to Spring Framework's task scheduling. Spring batch scheduler
没有这样的东西,您指的是Spring Framework的任务调度。
Scheduling is incompatible with your requirement of "eg:after a method invocation/button click". 计划与您的“例如:方法调用/按钮单击后”的要求不兼容。 Scheduling implies knowing the schedule upfront, but in your case, you don't know upfront when the user will click the button. 计划意味着要事先知道计划,但是在您的情况下,您并不知道用户何时单击按钮。 What you actually need is to start a count down timer upon a user action. 您实际需要的是根据用户操作启动倒数计时器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.