关于ejb3.0定时服务的问题 [英] questions on ejb3.0 timer service

查看:233
本文介绍了关于ejb3.0定时服务的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Timersession bean中有4种方法,让我们说 a() b() c() d()




  • a()应每6小时执行一次

  • b()应每3小时执行一次

  • c()应每1小时执行一次



如何通过使用EJB 3.0定时服务来实现?

解决方案

p>当然可以创建多个定时器



示例代码:

  //  -  

@Schedules({
@Schedule(hour =* / 1),
@Schedule(hour =* / 3),
@Schedule(hour =* / 6)
})
public void timeOutHandler(){

if(currentHr%1 == 0)// - 检查小时超时
a();
else if(currentHr%3 == 0)// - 同样
b();
else if(currentHr%6 == 0)// - 同样
c();
}

// -


I have 4 methods in my Timersession bean,lets say a(), b(), c() and d().

  • a() should be executed every 6 hour
  • b() should be execute every 3 hour
  • c() should be execute every 1 hour

How can I do this by using EJB 3.0 timer service?

解决方案

Definitely, you can create multiple timers & can handle it in a single method.

Sample code :

//--

    @Schedules ({
        @Schedule(hour="*/1"),
        @Schedule(hour="*/3"),
        @Schedule(hour="*/6")
    })
    public void timeOutHandler(){

        if(currentHr % 1 == 0)  //-- Check for hourly timeout
            a();
        else if(currentHr % 3 == 0) //-- Similarly
            b();
        else if(currentHr % 6 == 0) //-- Similarly
            c();
    }

//--

这篇关于关于ejb3.0定时服务的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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