users@glassfish.java.net

EJB 3 Timers

From: <glassfish_at_javadesktop.org>
Date: Mon, 17 Aug 2009 11:23:05 PDT

I have been trying to get a timer to work for a long time. I keep getting null exceptions on the line when I create the timer. I tried sessioncontext way and just timerservice way but I'm getting no where with it. Can someone help me out?

Here is the code for the bean

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class Timers implements TimerLocal, TimedObject {
        @Resource
        SessionContext ctx = null;
        private TimerService ts;
        
        
    /**
     * Default constructor.
     */
        
        public Timers() {
        // TODO Auto-generated constructor stub
            
    }
         public void createTimer()
         {
                long testNum = 3000;
                ts.createTimer(testNum, null);
            System.out.println("checking");
         }
 
    @Timeout
    public void timeout(Timer time)
    {
            System.out.println("Timer Bean is working!!!!");
    }
        @Override
        public void ejbTimeout(Timer time) {
                // TODO Auto-generated method stub
                System.out.println("Timer Bean is working!!!!");
        }
}


client code
package client.session.TimerBean;

import session.TimerBean.*;
public class Client {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                Timers Test = new Timers();
                Test.createTimer();

        }

}

And the interface
package session.TimerBean;
import javax.ejb.Local;

@Local
public interface TimerLocal {
         public void createTimer();
}
[Message sent by forum member 'tannic2k7' (tannic2k7)]

http://forums.java.net/jive/thread.jspa?messageID=360810