In fact, asynchronous tasks should not even rely on @SessionScoped or 
@RequestScoped because they do not exist outside a servlet request ;)

LieGrue,
strub



----- Original Message -----
> From: Gerhard Petracek <gerhard.petra...@gmail.com>
> To: MyFaces Discussion <users@myfaces.apache.org>
> Cc: 
> Sent: Friday, February 17, 2012 10:58 AM
> Subject: Re: CODI+OWB+Scheduler, ContextNotActiveException
> 
> hi erwin,
> 
> first of all: welcome @ myfaces!
> 
> for a conversation a window is needed. therefore, the current conversation
> can't be resolved outside of a faces request.
> since it's possible to destroy the window-context at any time, it isn't
> suggested to use such scopes in an asynchronous task at all.
> 
> regards,
> gerhard
> 
> http://www.irian.at
> 
> Your JSF/JavaEE powerhouse -
> JavaEE Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces
> 
> 
> 
> 2012/2/17 Bonhold, Erwin <erwin.bonh...@atos.net>
> 
>>  Hi all,
>> 
>>  at first, CDI + CODI is really cool stuff for building a webapp.
>> 
>>  1) Our Environment:
>>  We are using OWB 1.1.3, CODI 1.0.2 on a Tomcat 7 environment with CODI
>>  @Transactional.
>> 
>>  Database Producer:
>>   @PersistenceContext(unitName = "myunit")
>>   private EntityManager extendedEntityManager;
>> 
>>   @Produces
>>   @ConversationScoped
>>   @MyQualifier
>>   public ExtendedEntityManager createExtendedEntityManager() {
>>   return new ExtendedEntityManager(this.extendedEntityManager);
>>   }
>> 
>>   public void dispose(@Disposes @Siemens ExtendedEntityManager
>>  extendedEntityManager) {
>>   if (extendedEntityManager.isOpen()) {
>>    extendedEntityManager.close();
>>   }
>>   }
>> 
>>  -DatabaseService which gets above EntityManager injected
>>  -OtherServices which getting the database Service injected
>> 
>> 
>>  2) The Problem:
>>  Using Quartz, Seam Cron or the following class, which creates a thread,
>>  leads into the same problem.
>> 
>>  @ApplicationScoped
>>  public class ApplicationTimer {
>> 
>>   @Inject
>>   private Log log;
>> 
>>   @Inject
>>   private OtherService otherService; // gets databaseService injected,
>>  databaseService gets EntityManager injected
>> 
>>   public void init() {
>>   log.info("initialize timer thread");
>>   try {
>>    otherService.doSomething(); // WORKS in Context of this
>>  ApplicationScoped bean
>>   } catch (Exception e) {
>>    log.error(e);
>>   }
>> 
>>   Thread timer = new Thread() {
>>    public void run() {
>>     while (true) {
>>      log.info("That's the thread");
>>      try {
>>       otherService.doSomething(); // EXCEPTION occurs in Child Thread
>>       Thread.sleep(5000);
>>      } catch (Exception e) {
>>       log.error(e);
>>      }
>>     }
>>    }
>>   };
>>   timer.start();
>>   }
>>  }
>> 
>>  An exception
>>  javax.enterprise.context.ContextNotActiveException: WebBeans context with
>>  scope type annotation @ConversationScoped does not exist within current
>>  thread
>>  occurs
>> 
>>  We also tried to start a (javax) Conversation. Leads into the same
>>  Excpetion with ... a @RequestScoped does not exist.
>> 
>>  The child thread is not in context of a web request, we guess the
>>  EntityManager have to (as descriped in CODI doc).
>> 
>>  But how to solve this problem?
>>  Is there a possibility to create/provide an appropriate context to the
>>  child thread or to start scheduled services in another way?
>> 
>> 
>>  Best Regards
>>  Erwin
>> 
>

Reply via email to