tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Russo <jru...@genscape.com>
Subject Singleton + Timer service
Date Mon, 08 Feb 2010 17:51:30 GMT
Good afternoon everyone,

I have a question about the ejb timer services with the new singleton
beans.  What I want to do is create a timer service that starts on
openejb startup, so I thought it would be perfect to use the singleton
bean for this purpose.  However, when I try to create the timer in the
singleton post-construct method, I get this error:

java.lang.IllegalStateException: TimerService method not permitted for
current operation POST_CONSTRUCT

Is this a bug, an incomplete implementation, or by design?  I suppose I
can work around by using a servlet context listener, but I figured
singleton beans would be cleaner.

-----------------------------------------------------------------------------------------------------
Here is my singleton class:

@Singleton(name="TimerServiceTest")
@Startup
public class TimerServiceTestBean implements TimerServiceTestLocal {
    private static Logger _log =
Logger.getLogger(TimerServiceTestBean.class);
    private volatile static Timer _timer;
    
    @Resource
    private TimerService _timerService;

    @PostConstruct
    public void onStartup() {
        _timer = _timerService.createTimer(60000, 60000, null);
        _log.info("Starting TimerServiceTestBean timer.");
    }

    @PreDestroy
    public void onShutdown() {
        _timer.cancel();
        _log.info("Shutting down TimerServiceTestBean timer.");
    }

    @Timeout
    public void onTimeout(Timer timer) {
        _log.info("TimeServiceTestBean has just received a timeout
notice at "
                + (new Date()).toString());
    }
}




Jason Russo

Application Developer

Genscape– See the Energy

445 E. Market St, Suite 200

Louisville, KY 40202

Tel: 502-583-2091

www.genscape.com




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message