2

我想每两秒唤醒一次 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 容器不会在每两秒后唤醒调度程序。

对此有何建议?我怎样才能使表情每两秒钟醒来一次。

谢谢,甘扬。

4

1 回答 1

3

有两件事可能会导致问题:

  1. import 语句似乎不正确,它是com.sun.jersey.spi.resource.Singleton,但应该是javax.ejb.Singleton

  2. 尝试删除@LocalBean注释。

于 2012-06-07T08:39:26.270 回答