EJB @Timeout无效

时间:2012-06-02 06:08:29

标签: timer ejb-3.1

我想每两秒唤醒一次ejb计时器。为此,我正在创建 ScheulerExpression ,如下面的代码......

package com.fks.nclp.ejb.timer.service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.ScheduleExpression;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;

import com.sun.jersey.spi.resource.Singleton;


@LocalBean
@Singleton
@Startup
public class HelloWorldService {


    @Resource
    TimerService timerService;

    @PostConstruct
    public void initialize(){
            System.out.println("EJB PRE CONSTRUCT");
            ScheduleExpression expression = new ScheduleExpression();

            //SET TIMER TO 2 SEC            
            expression.hour("*");
            expression.minute("*");
            expression.second("*/2");

            timerService.createCalendarTimer(expression,new TimerConfig("TimerScheduler",false));


    }


    @Timeout
    public void startTimer(){
        System.out.println("THIS IS EJB TIMER PROGRAM");
    }

}

但是...... EJB容器并没有在每两秒钟后唤醒调度程序。

对此有何建议? 我怎样才能让表达式每两秒唤醒一次。

谢谢, Gunjan。

1 个答案:

答案 0 :(得分:3)

有两件事可能导致问题:

  1. 导入语句似乎不正确,com.sun.jersey.spi.resource.Singleton,但应为javax.ejb.Singleton

  2. 尝试删除@LocalBean注释。