tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: Regarding CDI scope and @Asynchronous EJB methods
Date Mon, 06 Oct 2014 15:51:56 GMT
2014-10-06 17:24 GMT+02:00 John D. Ament <john.d.ament@gmail.com>:
> Hi,
>
> I would say no to #2.  Thread != RequestScoped.  If you want to start a
> request scope with the thread, DeltaSpike has a CDIControl module that can
> do this for you.
>
> John
>
> On Mon, Oct 6, 2014 at 11:08 AM, Lars-Fredrik Smedberg <itsmeden@gmail.com>
> wrote:
>
>> When executing an EJB @Asynchronous method I know that valid CDI scopes are
>> request and application.
>>
>> 1. Since @ApplicationScoped beans are available I assume that its better to
>> inject those in the actual code being executed rather than passing them as
>> arguments to the @Asynchronous method, correct?
>> 2. Since the @Asynchronous method starts a new thread any @RequestScoped
>> beans passed in will be recreated right when the first business method on
>> them are called, correct?
>> 3. The above leaves me (if correct) with choosing between passing a normal
>> POJO (created with new) or an injected @Dependent scoped CDI Managed Bean
>> to an @Asynchronous EJB method, the choice depends on wether the object
>> passed needs to inject anything, correct?
>>

General rule regarding @Async (and all async stuff like timers) is:
use message passing pattern, ie pass all you need when invoking the
method. You can for sure go further but this is most of the time hard
to maintain and impossible to debug.

>> --
>> Med vänlig hälsning / Best regards
>>
>> Lars-Fredrik Smedberg
>>
>> STATEMENT OF CONFIDENTIALITY:
>> The information contained in this electronic message and any
>> attachments to this message are intended for the exclusive use of the
>> address(es) and may contain confidential or privileged information. If
>> you are not the intended recipient, please notify Lars-Fredrik Smedberg
>> immediately at itsmeden@gmail.com, and destroy all copies of this
>> message and any attachments.
>>

Mime
View raw message