Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 39F799891 for ; Fri, 17 Feb 2012 10:07:12 +0000 (UTC) Received: (qmail 63441 invoked by uid 500); 17 Feb 2012 10:07:11 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 63395 invoked by uid 500); 17 Feb 2012 10:07:11 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 63387 invoked by uid 99); 17 Feb 2012 10:07:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2012 10:07:11 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of gerhard.petracek@gmail.com designates 209.85.161.181 as permitted sender) Received: from [209.85.161.181] (HELO mail-gx0-f181.google.com) (209.85.161.181) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2012 10:07:05 +0000 Received: by ggnv5 with SMTP id v5so1860995ggn.12 for ; Fri, 17 Feb 2012 02:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=tTUEK+RA94W9F9eyXkEsbo4FHrZIV8VBOlGnWFnp9fs=; b=jY7swyhgvVtUfHmz4lrp8QIMlDZDRC9N68mscmgsRkNXOblk1I98KEkrDNDEcTPe7B Dr7+jZ3AcqHyuoprpsWCY07YnPj6dx7W5dZpDorBiR7FaXoEc7dhxGjgtYi4Ezo6e9qr PTKFKmYN0ecIohLtlV84aAdwWBZqaRnmd8Uzg= Received: by 10.236.148.143 with SMTP id v15mr8324605yhj.47.1329473204135; Fri, 17 Feb 2012 02:06:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.61.65 with HTTP; Fri, 17 Feb 2012 02:06:24 -0800 (PST) In-Reply-To: References: <91B903A5B9AEA244A9049C1036CF481911110C6F@DEFTHW99EZ1MSX.ww931.my-it-solutions.net> From: Gerhard Petracek Date: Fri, 17 Feb 2012 11:06:24 +0100 Message-ID: Subject: Re: CODI+OWB+Scheduler, ContextNotActiveException To: MyFaces Discussion Content-Type: multipart/alternative; boundary=20cf303a320b1226bb04b9261a42 X-Virus-Checked: Checked by ClamAV on apache.org --20cf303a320b1226bb04b9261a42 Content-Type: text/plain; charset=ISO-8859-1 short addition: just store all information which are needed to process the task in a storage which is valid outside of requests. + you can use e.g. @TransactionScoped (since codi 1.0.4 it also works outside of requests.) 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 Gerhard Petracek > 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 > > 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 >> > > --20cf303a320b1226bb04b9261a42--