1 Reply Latest reply on Aug 28, 2012 7:35 AM by Martin Kouba

    Use an ejbTimer in a CDI SessionScoped Bean

    Max Korn Newbie

      Hi all !

      My need is to use ejbTimer in a CDI based project. The timer fires a timeout if each user does not perform an activity within N minutes.

      My question is, can I associate (1:1) an ejbTimer for each @SessionScoped Bean ? in other words each user should have its timer running, until the bean is removed.

      Is it technically possible to achieve it ?


      (BTW that could be done with a mini-process designed in jBPM5 for example, however my requirement is to use just plain Java EE 6 Api)




        • 1. Re: Use an ejbTimer in a CDI SessionScoped Bean
          Martin Kouba Master

          Hi Max,

          I don't think so. Firstly EJB spec disallows timers for SFSBs (18.2 Bean Provider’s View of the Timer Service):

          Timers can be created for stateless session beans, singleton session beans, message-driven beans, and 2.1 entity beans. Timers cannot be created for stateful session beans.

          Secondly CDI session context is only active during the service() method of any servlet in the web application, during the doFilter() method of any servlet filter and when the container calls any HttpSessionListener, AsyncListener or ServletRequestListener (web request in short). In other words your session scoped CDI bean would not be available during the timeout callback invocation...


          However if you don't need to manipulate the session scoped bean during timeout place the timer on SLSB and identify it with session id... HTH.