栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

可以在运行时为@Schedule注释更改ejb参数吗?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

可以在运行时为@Schedule注释更改ejb参数吗?

@Schedule
用于容器在部署期间创建的自动计时器。

另一方面,可以使用

TimerService
它允许您在运行时定义何时
@Timeout
应调用该方法。

这可能是您感兴趣的材料:Java EE 6教程-使用Timer
Service

编辑: 只是为了使这个答案更完整。如果这是一个问题, 那么 答案是否可能- 是的。

有一种方法可以更改由创建的自动计时器的参数

@Schedule
。然而,这是非常 不寻常的 -它取消了自动计时器并创建了类似的程序化计时器:

// Automatic timer - run every 5 seconds// It's a automatic (@Schedule) and programmatic (@Timeout) timer timeout method// at the same time (which is UNUSUAL)@Schedule(hour = "*", minute = "*", second = "*/5")@Timeoutpublic void myScheduler(Timer timer) {    // This might be checked basing on i.e. timer.getInfo().    firstSchedule = ...    if (!firstSchedule) {        // ordinary pre for the scheduler    } else {        // Get actual schedule expression.        // It's the first invocation, so it's equal to the one in @Schedule(...)        Scheduleexpression expr = timer.getSchedule();        // Your new expression from now on        expr.second("*/7");        // timers is TimerService object injected using @Resource TimerService.        // Create new timer based on modified expression.        timers.createCalendarTimer(expr);        // Cancel the timer created with @Schedule annotation.        timer.cancel();    }}

再说一次-就我个人而言,我永远不会使用这样的代码,也永远不想在真实的项目中看到类似的东西:-)定时器是:

  • 自动 ,是通过
    @Schedule
    对值进行硬编码或在ejb-jar.xml中定义它们来创建的,
  • 程序化的 ,由应用程序代码创建,该代码在运行时可以具有不同的值。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402122.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号