3 Replies Latest reply on Mar 31, 2012 12:35 PM by christopherp

    Weld CDI context propagation

    Ivan Ivanov Newbie

      Hi, friends!

      I'm using the @SessionScoped CDI bean, which works perfectly. But the fact is that during the execution I have to create a new thread (I'm using the @Asynchronous annotation for this purpose). And, of course, weld doesn't propagate the @SessionScoped bean to the newly created thread. I've found some information about this issue here:

      http://seamframework.org/Documentation/IfICreateAThreadInMyCDIBeanHowWillWeldReact

       

      But I wasn't able to solve my problem. Is it possible to propagate the Context to newly created thread too?

      For example:

       

      @Stateless

      public class Runner {

            

          @Inject

          private MySession session; // this is the @SessionScoped bean

         

          // this method will be called in a new thread

          @Asynchronous

          public void doTask() { 

              // do some heavy long running work

               ...

              session.setResult(result); // oops - an error:

              // WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped

          }

         

      }

       

      Thanks!