users@glassfish.java.net

Re: EJB 3 Timers

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 17 Aug 2009 12:26:01 -0700

If you create a bean using new, nothing will be injected in that bean.

Regards,
-marina

glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>