1 Reply Latest reply on Aug 15, 2008 9:17 AM by jaikiran pai

    JBoss 4.2.2 and TimerService null pointer exception

    Kyle Bober Newbie

      I have a Stateless session bean that is also a WebService. When I attempt to inject a TimerService and create a new timer Instance the TimerService is always returned as null. It seems the TimerService is never injected. I also attempted injecting the SessionContext as well using @Resource and obtaining the TimerService via the SessionContext but the SessionContext is also null. Here is the code:

      package somepackage;

      import java.rmi.RemoteException;
      import java.util.Date;
      import java.util.Set;

      import javax.annotation.Resource;
      import javax.ejb.Remote;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateless;
      import javax.ejb.Timeout;
      import javax.ejb.Timer;
      import javax.ejb.TimerService;
      import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebResult;
      import javax.jws.WebService;

      import org.jboss.annotation.ejb.RemoteBinding;
      import org.jboss.annotation.ejb.Service;

      /**
      * Class which contains each of the services calls used by the client side.
      * @author pcrane
      *
      */
      @WebService
      @Stateless
      @Remote(IMemberService.class)
      @RemoteBinding(jndiBinding="MemberService/remote")
      public class MemberService implements IMemberService
      {
      // @Resource
      // public SessionContext theSessionContext;

      @Resource
      public TimerService theTimerService;

      @Timeout
      public void deleteUnauthorizedMembers(Timer aTimer) throws RemoteException
      {
      Long memberID = (Long) aTimer.getInfo();
      MemberServiceImpl.deleteMember(memberID);
      }

      /* (non-Javadoc)
      * @see com.thesearchagency.transformer.services.member.IMemberService#memberServiceUpdateAccount()
      */
      @WebMethod
      @WebResult(name = "memberID")
      public String memberServicePersistMember(@WebParam(name="memberProfile") MemberServiceUser aUser) throws RemoteException
      {
      TimerService ts = theSessionContext.getTimerService();
      ts.createTimer(timerExecutionDate, aUser.getMemberId());
      return MemberServiceImpl.memberServicePersistMember(aUser);
      }
      }



      package somepackage;

      import java.rmi.RemoteException;
      import java.util.Date;
      import java.util.Set;

      public interface IMemberService
      {
      String memberServicePersistMember(MemberServiceUser aUser) throws RemoteException;
      }

      Please help! I ahve been racking my brain on this for a few hours now and Timers should be fairly easy in EJB3.0!

      Thanks,
      Kyle

        • 1. Re: JBoss 4.2.2 and TimerService null pointer exception
          jaikiran pai Master

           

          "kyle.bober" wrote:
          I have a Stateless session bean that is also a WebService. When I attempt to inject a TimerService and create a new timer Instance the TimerService is always returned as null. It seems the TimerService is never injected.


          I have not tried injecting the TimerService in any of my sample applications. So i am not sure whether that is working or not. But i just found this open issue in the JIRA https://jira.jboss.org/jira/browse/EJBTHREE-1391


          "kyle.bober" wrote:

          I also attempted injecting the SessionContext as well using @Resource and obtaining the TimerService via the SessionContext but the SessionContext is also null.


          I don't think there should be a problem with the SessionContext injection. Post your exact code and also the exception stacktrace and the server.log logs (from the point when your application is being deployed). Which version of JBoss and Java do you use?

          P.S: While posting logs or xml content or code, remember to wrap it in a code block, by using the Code button in the message editor window. Please hit the Preview button before posting to ensure that the post is correctly formatted.