MethodInvokingTimerTaskFactoryBean 已弃用,我应该改用什么类? [英] MethodInvokingTimerTaskFactoryBean is deprecated, what class should I be using instead?

查看:61
本文介绍了MethodInvokingTimerTaskFactoryBean 已弃用,我应该改用什么类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务类,我需要根据配置参数定期(固定速率)执行一个方法.最初我打算使用 Java TimerTask 然后配置一个计时器来运行它.然后还要配合spring应用上下文生命周期事件停止,启动所说的定时器.

I have a service class that I need to execute a method on a regular basis (fixed rate) based upon a configuration parameter. Originally I was going to use the Java TimerTask and then configure a timer to run it. Then also tie in spring application context lifecycle events to stop, start the said timer.

当解析他们的我遇到的文档.这提供了一个很好的好处,这个任务的生命周期可以由 spring 自动为我管理.此外,允许可扩展性,如果我想把它扔到 Quartz 或实现某种其他调度实现,它更多的是配置更改而不是代码更改.

When parsing their documentation I came across this. This offers a nice benefit that this task's life cycle can be managed by spring automatically for me. Also, allows scale-ability such that if I wanted to throw this into Quartz or implement some sort of other scheduling implementation, it is more of a configuration change as opposed to code changes.

听起来很诱人,但后来我查看了他们的java 文档并发现该类已被弃用

It sounded really enticing but then I checked out their java docs and discovered that the class is deprecated

弃用说明表明开发人员应该改用 spring.scheduling.concurrent 包.但是,该包不包含任何提供 Runnable 接口抽象的类似类(我想这样做).这个功能在春天不再可用了吗?我的服务类是否应该实现 Runnable 接口,然后简单地让该方法调用我的服务接口定义的方法?

The deprecation notes indicate that developers should be using the spring.scheduling.concurrent package instead. However, that package does not include any similar class that offers abstraction of the Runnable interface (which I would like to do). Is this functionality not available anymore in spring? Should my service class implement the Runnable interface then and simply have that method invoke my Service Interface defined method?

推荐答案

我最终采用了以下解决方案:

I ended up going with the following solution:

<!-- Scheduled tasks to be exectued -->
<task:scheduled-tasks scheduler="scheduler">
    <task:scheduled ref="myClass" method="myMethod" fixed-rate="${some.value}"/>
</task:scheduled-tasks>

<!-- The scheduler that executes scheduled tasks -->
<task:scheduler id="scheduler" pool-size="5"/>

这篇关于MethodInvokingTimerTaskFactoryBean 已弃用,我应该改用什么类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆