3 Replies Latest reply: Nov 15, 2012 5:19 AM by Martin Kouba RSS

@Schedule and @RequestScoped beans

Marcel Šebek Newbie

I'm seeing a strange behavior of @javax.ejb.Schedule methods with relation to CDI contexts. I have a request scoped bean with producer and disposer handler:

 

public class Factory {

     @Produces @RequestScoped

     public MyConnection createConnection() {

          System.out.println("creating connection");

          return new MyConnection();

     }

 

     public void disposeConnection(@Disposes MyConnection connection) {

          System.out.println("disposing connection");

     }

}

 

and an ejb (either stateless or singleton) with timer method:

 

@Stateless

or

@Singleton @Startup

public class MyEJB {

     @Inject

     private MyConnection conn;

 

     @Schedule(second = "*/5", minute = "*", hour = "*")

     public void timeout() {

          System.out.println("timer called");

     }

}

 

I see that for each call, a new connection is produced but no connection is disposed which leads to fast connection pool exhaustion. Can anyone tell me whether this type of injection is unsupported or if it is a bug in weld?

  • 1. Re: @Schedule and @RequestScoped beans
    napu Newbie

    No help here, but I noticed the same today (when producing JMS resources).

     

    The @Disposes method works when the @RequestScoped annotation is removed (but then the producer does not work as intended).

  • 2. Re: @Schedule and @RequestScoped beans
    Maxim Usoltsev Newbie

    I'm also getting same behavior not only for @Schedule method, but for onMessage() method of @MessageDriven bean too. (JBoss AS 7.1.1.Final "Brontes")

    Also @PreDestoy method not invoked for @RequestScoped beans.

    Is there any workaround for this situation ?

    Maybe we can somehow start and finish "request" programmatically so weld will call all needed (@PreDestroy, @Dispose) methods ?

  • 3. Re: @Schedule and @RequestScoped beans
    Martin Kouba Master

    Hi,

    this is a know issue in AS7 integration component - the request context is not destroyed properly, that's why neither the disposer method nor the predestory callback is invoked - see AS7-4280. AFAIK this affects asynchronous methods as well.