EJB 3.x中@Schedule方法的动态参数 [英] Dynamic parameters for @Schedule method in an EJB 3.x

查看:97
本文介绍了EJB 3.x中@Schedule方法的动态参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是J2EE6中@Schedule注释的新手

I'm new to the @Schedule annotations in J2EE6

我想在EJB 3.x和Glassfish 3.1上运行作业。

I want to run a job using EJB 3.x with Glassfish 3.1.

javax.ejb.Schedule对我们来说似乎是一个不错的选择,因此我们可以将自定义时间视为:

The javax.ejb.Schedule seems to be a good choice for us, so we could think of our custom time as something like:

@Singleton
public class CustomTimer {
    @EJB
    SettingsFacade settingsFacade;

    @Schedule(second="someSecondParameter", minute="someMinuteParameter",hour="someHourParameter", persistent=false)
    public void executeTimer(){
        //Code executing something against database using the settingsFacade
    }
}

在这里,我们要从数据库获取的参数,因此每个月都要更改。对此有任何干净的解决方案?

Here, we want the parameters to be got from database, so they are changed every month. Any clean solution for this?

推荐答案

不, @Schedule ,因为注释属性通常应为编译时间常数。

No, there is no solution with @Schedule, because annotation attributes in general should be compile time constants.

如果需要更大的灵活性,请程序计时器
然后还必须轮询数据库以更改配置,并删除现有计时器并创建新计时器。

When more flexibility is needed, programmatic timers can be used. Also then polling database for changed configuration and removing existing and creating new timers must be implemented.

这篇关于EJB 3.x中@Schedule方法的动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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