You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Lars-Fredrik Smedberg <it...@gmail.com> on 2014/04/10 15:37:24 UTC

Design - CDI and worker threads

Hi

If I within a thread wishes to start asynchronous "jobs" using the
ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
Future-result within that same thread I run into the following exception:

"WebBeans context with scope type annotation @RequestScoped does not exist
within current thread"

which is understandable since the managed bean passed used in the Callable
passed to ExecutorService.submit(...) contains injected beans iteself that
are @RequestScoped.

Is there any way around this? Suggestions on changing the design perhaps?

Regards
Lars-Fredrik Smedberg


-- 
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.

Re: Design - CDI and worker threads

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
I suppose there is no CDI implementation independent way of doing this? We
tried to use Deltaspike before but ran into problem with WAS 8.5.5....
On Apr 10, 2014 5:52 PM, "Romain Manni-Bucau" <rm...@gmail.com> wrote:

> actually @Asynch doesn't mandates to start cdi contexts so request
> scopes can or not be here but transactions are handled if you remove
> transaction management.
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> > Hi Lars-Fredrik!
> >
> > This is one of the rare situations where @Asynchronous is good
> >
> > @Stateless
> > @TransactionManagement(TransactionManagementType.BEAN)
> > public class ThreadExecutorEjb {
> >
> >     @Asynchronous
> >     public void executeTask(Runnable work, Object config) {
> >         work.run();
> >     }
> > }
> >
> > The problem with this approach is that WAS is _really_ picky (and far
> from
> > the spec imo) when it comes to transactions.
> > You might play a bit with the TransactionManagement and other stuff
> > probably.
> >
> > LieGrue,
> > strub
> > On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> > <rm...@gmail.com> wrote:
> >
> > Hmm deltaspike is a lib you can put in your app but if you really want
> > to get rid of it you can copy
> >
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> > Romain Manni-Bucau
> > Twitter: @rmannibucau
> > Blog: http://rmannibucau.wordpress.com/
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > Github: https://github.com/rmannibucau
> >
> >
> >
> > 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> Hi
> >>
> >> Thanks for the hint, however I'm not able to use Deltaspike but only the
> >> OpenWebbeans included with WebSphere 8.5.5.x...
> >>
> >> How can I do this with OpenWebbeans only?
> >>
> >> Regards
> >> Lars-Fredrik
> >>
> >>
> >> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
> >> <rm...@gmail.com>
> >> wrote:
> >>>
> >>> Hi
> >>>
> >>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
> >>> executorService to do it and it should be fine:
> >>> http://openwebbeans.apache.org/testing_cdictrl.html
> >>> Romain Manni-Bucau
> >>> Twitter: @rmannibucau
> >>> Blog: http://rmannibucau.wordpress.com/
> >>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>> Github: https://github.com/rmannibucau
> >>>
> >>>
> >>>
> >>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >>> > Hi
> >>> >
> >>> > If I within a thread wishes to start asynchronous "jobs" using the
> >>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
> >>> > the
> >>> > Future-result within that same thread I run into the following
> >>> > exception:
> >>> >
> >>> > "WebBeans context with scope type annotation @RequestScoped does not
> >>> > exist
> >>> > within current thread"
> >>> >
> >>> > which is understandable since the managed bean passed used in the
> >>> > Callable
> >>> > passed to ExecutorService.submit(...) contains injected beans iteself
> >>> > that
> >>> > are @RequestScoped.
> >>> >
> >>> > Is there any way around this? Suggestions on changing the design
> >>> > perhaps?
> >>> >
> >>> > Regards
> >>> > Lars-Fredrik Smedberg
> >>> >
> >>> >
> >>> > --
> >>> > 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.
> >>
> >>
> >>
> >>
> >> --
> >> 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.
> >
> >
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
shouldn't work for sure in tomee *by default*.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-11 8:52 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> Concurrency utils is a completely different spec and IS broken as it does
> _not_ define it properly. But for @Asynchronous it's perfectly well defined
> in the spec.
>
> I use this as thread starter for BatchEE and I've tested it in
> * TomEE
> * WAS-8.0.0.6
> * WAS-8.5.5.1
> * JBossAS-7.0.3.Final
> * latest WildFly
>
> LieGrue,
> strub
>
>
> On Friday, 11 April 2014, 7:15, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> Ok about the spec but propagation doesnt work for sure (it is a kind of
> issue for concurrency utilities)
> You are right for the config but i just realize i was really not clear
> (throw new TooLateException). If you sont configure the container, you can
> use a semaphore with 20 permits and the container block you to 10. So it is
> important to have a look too and it can be enough avoiding custom
> potentially buggy code.
> Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :
>
>
>
>> But not propagated in async pool..and not in ejb 3.1
> Of course it is!
> But you wont find this in the EJB spec - you need to look in the EE umbrella
> spec and the CDI spec ;)
>
>
>> Ps: you can configure async pool or stateless pool
> Yes, some container allow to configure this. But I'm pretty sure there is
> nothing in the spec which requires it. So I'd rather hack it myself.
>
> LieGrue,
> strub
>
>
> On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau
> <rm...@gmail.com> wrote:
>
> Ps: you can configure async pool or stateless pool to limit concurrency
> depending the container...but a semaphore enforces it portably
>>Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a écrit
>> :
>>
>>But not propagated in async pool..and not in ejb 3.1
>>>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
>>>
>>>
>>>>
>>>>Nope, not right.
>>>>The CDI spec mandates that @RequestScoped is active for all EJB calls.
>>>> And every subsequent invocation as well of course.
>>>>
>>>>LieGrue,
>>>>strub
>>>>
>>>>
>>>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau
>>>> <rm...@gmail.com> wrote:
>>>>
>>>>actually @Asynch doesn't mandates to start cdi contexts so request
>>>>>scopes can or not be here but transactions are handled if you remove
>>>>>transaction management.
>>>>>Romain Manni-Bucau
>>>>>Twitter: @rmannibucau
>>>>>Blog: http://rmannibucau.wordpress.com/
>>>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>Github: https://github.com/rmannibucau
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>>>>>> Hi Lars-Fredrik!
>>>>>>
>>>>>> This is one of the rare situations where @Asynchronous is good
>>>>>>
>>>>>> @Stateless
>>>>>> @TransactionManagement(TransactionManagementType.BEAN)
>>>>>> public class ThreadExecutorEjb {
>>>>>>
>>>>>>     @Asynchronous
>>>>>>     public void executeTask(Runnable work, Object config) {
>>>>>>         work.run();
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> The problem with this approach is that WAS is _really_ picky (and far
>>>>>> from
>>>>>> the spec imo) when it comes to transactions.
>>>>>> You might play a bit with the TransactionManagement and other stuff
>>>>>> probably.
>>>>>>
>>>>>> LieGrue,
>>>>>> strub
>>>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>>>>>> <rm...@gmail.com> wrote:
>>>>>>
>>>>>> Hmm deltaspike is a lib you can put in your app but if you really want
>>>>>> to get rid of it you can copy
>>>>>>
>>>>>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>>>>>> Romain Manni-Bucau
>>>>>> Twitter: @rmannibucau
>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> Github: https://github.com/rmannibucau
>>>>>>
>>>>>>
>>>>>>
>>>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>> Hi
>>>>>>>
>>>>>>> Thanks for the hint, however I'm not able to use Deltaspike but only
>>>>>>> the
>>>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>>>>>
>>>>>>> How can I do this with OpenWebbeans only?
>>>>>>>
>>>>>>> Regards
>>>>>>> Lars-Fredrik
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>>>>>>> <rm...@gmail.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate
>>>>>>>> your
>>>>>>>> executorService to do it and it should be fine:
>>>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>>>>>> Romain Manni-Bucau
>>>>>>>> Twitter: @rmannibucau
>>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg
>>>>>>>> <it...@gmail.com>:
>>>>>>>> > Hi
>>>>>>>> >
>>>>>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait
>>>>>>>> > for
>>>>>>>> > the
>>>>>>>> > Future-result within that same thread I run into the following
>>>>>>>> > exception:
>>>>>>>> >
>>>>>>>> > "WebBeans context with scope type annotation @RequestScoped does
>>>>>>>> > not
>>>>>>>> > exist
>>>>>>>> > within current thread"
>>>>>>>> >
>>>>>>>> > which is understandable since the managed bean passed used in the
>>>>>>>> > Callable
>>>>>>>> > passed to ExecutorService.submit(...) contains injected beans
>>>>>>>> > iteself
>>>>>>>> > that
>>>>>>>> > are @RequestScoped.
>>>>>>>> >
>>>>>>>> > Is there any way around this? Suggestions on changing the design
>>>>>>>> > perhaps?
>>>>>>>> >
>>>>>>>> > Regards
>>>>>>>> > Lars-Fredrik Smedberg
>>>>>>>> >
>>>>>>>> >
>>>>>>>> > --
>>>>>>>> > 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.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> 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.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>
>>
>
>
>

Re: Design - CDI and worker threads

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi

@Mark

I tried this today in Websphere Liberty Profile April Beta which has
support for EJB and asynchronous method invocation and I have the following
questions about the scope:

- If I in the method that executes the @Asynchronous method injects a
request scoped, session scoped and application scoped bean will I get a new
contextual instance for the request scoped bean and the same contextual
isntances for the session and application scoped beans?
- We do not use DeltaSpike but use the same construction as DeltaSpike has
in the ServletContextHolderListener class but the contextInitialized method
does not seem to be invoked so our class that corresponds to
ServletContextHolder
does not have a bound ServletContext. This makes it not possible to access
e.g. HttpRequest parameters etc. Is there a way around that or do we do
something wrong here?

Regards
Lars-Fredrik Smedberg


On Fri, Apr 11, 2014 at 2:12 PM, Mark Struberg <st...@yahoo.de> wrote:

> yes that is exactly what I do. In WAS and also in TomEE ;)
>
> LieGrue,
> strub
>    On Friday, 11 April 2014, 9:42, Lars-Fredrik Smedberg <
> itsmeden@gmail.com> wrote:
>
> Hi Mark
>
> Just so I understand it correctly.
>
> I can @Inject  a @Stateless bean once and call its @Asynchronous annotated
> method multiple times to create threads that can process work that uses CDI
> managed beans?
>
> Thanks
> Lars-Fredrik
>
>
> On Fri, Apr 11, 2014 at 8:52 AM, Mark Struberg <st...@yahoo.de> wrote:
>
> Concurrency utils is a completely different spec and IS broken as it does
> _not_ define it properly. But for @Asynchronous it's perfectly well defined
> in the spec.
>
> I use this as thread starter for BatchEE and I've tested it in
> * TomEE
> * WAS-8.0.0.6
> * WAS-8.5.5.1
> * JBossAS-7.0.3.Final
> * latest WildFly
>
> LieGrue,
> strub
>
>
>    On Friday, 11 April 2014, 7:15, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Ok about the spec but propagation doesnt work for sure (it is a kind of
> issue for concurrency utilities)
> You are right for the config but i just realize i was really not clear
> (throw new TooLateException). If you sont configure the container, you can
> use a semaphore with 20 permits and the container block you to 10. So it is
> important to have a look too and it can be enough avoiding custom
> potentially buggy code.
> Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :
>
>
>
> > But not propagated in async pool..and not in ejb 3.1
> Of course it is!
> But you wont find this in the EJB spec - you need to look in the EE
> umbrella spec and the CDI spec ;)
>
>
> > Ps: you can configure async pool or stateless pool
> Yes, some container allow to configure this. But I'm pretty sure there is
> nothing in the spec which requires it. So I'd rather hack it myself.
>
> LieGrue,
> strub
>
>
> On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Ps: you can configure async pool or stateless pool to limit concurrency
> depending the container...but a semaphore enforces it portably
> >Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a
> écrit :
> >
> >But not propagated in async pool..and not in ejb 3.1
> >>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
> >>
> >>
> >>>
> >>>Nope, not right.
> >>>The CDI spec mandates that @RequestScoped is active for all EJB calls.
> And every subsequent invocation as well of course.
> >>>
> >>>LieGrue,
> >>>strub
> >>>
> >>>
> >>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
> >>>
> >>>actually @Asynch doesn't mandates to start cdi contexts so request
> >>>>scopes can or not be here but transactions are handled if you remove
> >>>>transaction management.
> >>>>Romain Manni-Bucau
> >>>>Twitter: @rmannibucau
> >>>>Blog: http://rmannibucau.wordpress.com/
> >>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>Github: https://github.com/rmannibucau
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> >>>>> Hi Lars-Fredrik!
> >>>>>
> >>>>> This is one of the rare situations where @Asynchronous is good
> >>>>>
> >>>>> @Stateless
> >>>>> @TransactionManagement(TransactionManagementType.BEAN)
> >>>>> public class ThreadExecutorEjb {
> >>>>>
> >>>>>     @Asynchronous
> >>>>>     public void executeTask(Runnable work, Object config) {
> >>>>>         work.run();
> >>>>>     }
> >>>>> }
> >>>>>
> >>>>> The problem with this approach is that WAS is _really_ picky (and
> far from
> >>>>> the spec imo) when it comes to transactions.
> >>>>> You might play a bit with the TransactionManagement and other stuff
> >>>>> probably.
> >>>>>
> >>>>> LieGrue,
> >>>>> strub
> >>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> >>>>> <rm...@gmail.com> wrote:
> >>>>>
> >>>>> Hmm deltaspike is a lib you can put in your app but if you really
> want
> >>>>> to get rid of it you can copy
> >>>>>
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> >>>>> Romain Manni-Bucau
> >>>>> Twitter: @rmannibucau
> >>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>> Github: https://github.com/rmannibucau
> >>>>>
> >>>>>
> >>>>>
> >>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >>>>>> Hi
> >>>>>>
> >>>>>> Thanks for the hint, however I'm not able to use Deltaspike but
> only the
> >>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
> >>>>>>
> >>>>>> How can I do this with OpenWebbeans only?
> >>>>>>
> >>>>>> Regards
> >>>>>> Lars-Fredrik
> >>>>>>
> >>>>>>
> >>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
> >>>>>> <rm...@gmail.com>
> >>>>>> wrote:
> >>>>>>>
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate
> your
> >>>>>>> executorService to do it and it should be fine:
> >>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
> >>>>>>> Romain Manni-Bucau
> >>>>>>> Twitter: @rmannibucau
> >>>>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>>>> Github: https://github.com/rmannibucau
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <
> itsmeden@gmail.com>:
> >>>>>>> > Hi
> >>>>>>> >
> >>>>>>> > If I within a thread wishes to start asynchronous "jobs" using
> the
> >>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait
> for
> >>>>>>> > the
> >>>>>>> > Future-result within that same thread I run into the following
> >>>>>>> > exception:
> >>>>>>> >
> >>>>>>> > "WebBeans context with scope type annotation @RequestScoped does
> not
> >>>>>>> > exist
> >>>>>>> > within current thread"
> >>>>>>> >
> >>>>>>> > which is understandable since the managed bean passed used in the
> >>>>>>> > Callable
> >>>>>>> > passed to ExecutorService.submit(...) contains injected beans
> iteself
> >>>>>>> > that
> >>>>>>> > are @RequestScoped.
> >>>>>>> >
> >>>>>>> > Is there any way around this? Suggestions on changing the design
> >>>>>>> > perhaps?
> >>>>>>> >
> >>>>>>> > Regards
> >>>>>>> > Lars-Fredrik Smedberg
> >>>>>>> >
> >>>>>>> >
> >>>>>>> > --
> >>>>>>> > 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.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> 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.
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >
> >
>
>
>
>
>
>
> --
> 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.
>
>
>


-- 
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.

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.
yes that is exactly what I do. In WAS and also in TomEE ;)


LieGrue,
strub

On Friday, 11 April 2014, 9:42, Lars-Fredrik Smedberg <it...@gmail.com> wrote:
 
Hi Mark
>
>
>Just so I understand it correctly.
>
>
>I can @Inject  a @Stateless bean once and call its @Asynchronous annotated method multiple times to create threads that can process work that uses CDI managed beans?
>
>
>Thanks
>Lars-Fredrik
>
>
>
>On Fri, Apr 11, 2014 at 8:52 AM, Mark Struberg <st...@yahoo.de> wrote:
>
>Concurrency utils is a completely different spec and IS broken as it does _not_ define it properly. But for @Asynchronous it's perfectly well defined in the spec.
>>
>>I use this as thread starter for BatchEE and I've tested it in 
>>* TomEE
>>* WAS-8.0.0.6
>>* WAS-8.5.5.1
>>* JBossAS-7.0.3.Final
>>* latest WildFly
>>
>>LieGrue,
>>strub
>>
>>
>>
>>
>>On Friday, 11 April 2014, 7:15, Romain Manni-Bucau <rm...@gmail.com> wrote:
>> 
>>Ok about the spec but propagation doesnt work for sure (it is a kind of issue for concurrency utilities)
>>>You are right for the config but i just realize i was really not clear (throw new TooLateException). If you sont configure the container, you can use a semaphore with 20 permits and the container block you to 10. So it is important to have a look too and it can be enough avoiding custom potentially buggy code.
>>>Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :
>>>
>>>
>>>>
>>>>> But not propagated in async pool..and not in ejb 3.1
>>>>Of course it is!
>>>>But you wont find this in the EJB spec - you need to look in the EE umbrella spec and the CDI spec ;)
>>>>
>>>>
>>>>> Ps: you can configure async pool or stateless pool
>>>>Yes, some container allow to configure this. But I'm pretty sure there is nothing in the spec which requires it. So I'd rather hack it myself.
>>>>
>>>>LieGrue,
>>>>strub
>>>>
>>>>
>>>>On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <rm...@gmail.com> wrote:
>>>>
>>>>Ps: you can configure async pool or stateless pool to limit concurrency depending the container...but a semaphore enforces it portably
>>>>>Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a écrit :
>>>>>
>>>>>But not propagated in async pool..and not in ejb 3.1
>>>>>>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
>>>>>>
>>>>>>
>>>>>>>
>>>>>>>Nope, not right.
>>>>>>>The CDI spec mandates that @RequestScoped is active for all EJB calls. And every subsequent invocation as well of course.
>>>>>>>
>>>>>>>LieGrue,
>>>>>>>strub
>>>>>>>
>>>>>>>
>>>>>>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <rm...@gmail.com> wrote:
>>>>>>>
>>>>>>>actually @Asynch doesn't mandates to start cdi contexts so request
>>>>>>>>scopes can or not be here but transactions are handled if you remove
>>>>>>>>transaction management.
>>>>>>>>Romain Manni-Bucau
>>>>>>>>Twitter: @rmannibucau
>>>>>>>>Blog: http://rmannibucau.wordpress.com/
>>>>>>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>>Github: https://github.com/rmannibucau
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>>>>>>>>> Hi Lars-Fredrik!
>>>>>>>>>
>>>>>>>>> This is one of the rare situations where @Asynchronous is good
>>>>>>>>>
>>>>>>>>> @Stateless
>>>>>>>>> @TransactionManagement(TransactionManagementType.BEAN)
>>>>>>>>> public class ThreadExecutorEjb {
>>>>>>>>>
>>>>>>>>>     @Asynchronous
>>>>>>>>>     public void executeTask(Runnable work, Object config) {
>>>>>>>>>         work.run();
>>>>>>>>>     }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> The problem with this approach is that WAS is _really_ picky (and far from
>>>>>>>>> the spec imo) when it comes to transactions.
>>>>>>>>> You might play a bit with the TransactionManagement and other stuff
>>>>>>>>> probably.
>>>>>>>>>
>>>>>>>>> LieGrue,
>>>>>>>>> strub
>>>>>>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>>>>>>>>> <rm...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>> Hmm deltaspike is a lib you can put in your app but if you really want
>>>>>>>>> to get rid of it you can copy
>>>>>>>>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>>>>>>>>> Romain Manni-Bucau
>>>>>>>>> Twitter: @rmannibucau
>>>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>>>>> Hi
>>>>>>>>>>
>>>>>>>>>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>>>>>>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>>>>>>>>
>>>>>>>>>> How can I do this with OpenWebbeans only?
>>>>>>>>>>
>>>>>>>>>> Regards
>>>>>>>>>> Lars-Fredrik
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>>>>>>>>>> <rm...@gmail.com>
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi
>>>>>>>>>>>
>>>>>>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>>>>>>>>>> executorService to do it and it should be fine:
>>>>>>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>>>>>>>>> Romain Manni-Bucau
>>>>>>>>>>> Twitter: @rmannibucau
>>>>>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>>>>>> > Hi
>>>>>>>>>>> >
>>>>>>>>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>>>>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
>>>>>>>>>>> > the
>>>>>>>>>>> > Future-result within that same thread I run into the following
>>>>>>>>>>> > exception:
>>>>>>>>>>> >
>>>>>>>>>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>>>>>>>>>> > exist
>>>>>>>>>>> > within current thread"
>>>>>>>>>>> >
>>>>>>>>>>> > which is understandable since the managed bean passed used in the
>>>>>>>>>>> > Callable
>>>>>>>>>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>>>>>>>>>> > that
>>>>>>>>>>> > are @RequestScoped.
>>>>>>>>>>> >
>>>>>>>>>>> > Is there any way around this? Suggestions on changing the design
>>>>>>>>>>> > perhaps?
>>>>>>>>>>> >
>>>>>>>>>>> > Regards
>>>>>>>>>>> > Lars-Fredrik Smedberg
>>>>>>>>>>> >
>>>>>>>>>>> >
>>>>>>>>>>> > --
>>>>>>>>>>> > 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.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 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.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>
>
>
>-- 
>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. 
>
>

Re: Design - CDI and worker threads

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi Mark

Just so I understand it correctly.

I can @Inject  a @Stateless bean once and call its @Asynchronous annotated
method multiple times to create threads that can process work that uses CDI
managed beans?

Thanks
Lars-Fredrik


On Fri, Apr 11, 2014 at 8:52 AM, Mark Struberg <st...@yahoo.de> wrote:

> Concurrency utils is a completely different spec and IS broken as it does
> _not_ define it properly. But for @Asynchronous it's perfectly well defined
> in the spec.
>
> I use this as thread starter for BatchEE and I've tested it in
> * TomEE
> * WAS-8.0.0.6
> * WAS-8.5.5.1
> * JBossAS-7.0.3.Final
> * latest WildFly
>
> LieGrue,
> strub
>
>
>    On Friday, 11 April 2014, 7:15, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Ok about the spec but propagation doesnt work for sure (it is a kind of
> issue for concurrency utilities)
> You are right for the config but i just realize i was really not clear
> (throw new TooLateException). If you sont configure the container, you can
> use a semaphore with 20 permits and the container block you to 10. So it is
> important to have a look too and it can be enough avoiding custom
> potentially buggy code.
> Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :
>
>
>
> > But not propagated in async pool..and not in ejb 3.1
> Of course it is!
> But you wont find this in the EJB spec - you need to look in the EE
> umbrella spec and the CDI spec ;)
>
>
> > Ps: you can configure async pool or stateless pool
> Yes, some container allow to configure this. But I'm pretty sure there is
> nothing in the spec which requires it. So I'd rather hack it myself.
>
> LieGrue,
> strub
>
>
> On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Ps: you can configure async pool or stateless pool to limit concurrency
> depending the container...but a semaphore enforces it portably
> >Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a
> écrit :
> >
> >But not propagated in async pool..and not in ejb 3.1
> >>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
> >>
> >>
> >>>
> >>>Nope, not right.
> >>>The CDI spec mandates that @RequestScoped is active for all EJB calls.
> And every subsequent invocation as well of course.
> >>>
> >>>LieGrue,
> >>>strub
> >>>
> >>>
> >>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
> >>>
> >>>actually @Asynch doesn't mandates to start cdi contexts so request
> >>>>scopes can or not be here but transactions are handled if you remove
> >>>>transaction management.
> >>>>Romain Manni-Bucau
> >>>>Twitter: @rmannibucau
> >>>>Blog: http://rmannibucau.wordpress.com/
> >>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>Github: https://github.com/rmannibucau
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> >>>>> Hi Lars-Fredrik!
> >>>>>
> >>>>> This is one of the rare situations where @Asynchronous is good
> >>>>>
> >>>>> @Stateless
> >>>>> @TransactionManagement(TransactionManagementType.BEAN)
> >>>>> public class ThreadExecutorEjb {
> >>>>>
> >>>>>     @Asynchronous
> >>>>>     public void executeTask(Runnable work, Object config) {
> >>>>>         work.run();
> >>>>>     }
> >>>>> }
> >>>>>
> >>>>> The problem with this approach is that WAS is _really_ picky (and
> far from
> >>>>> the spec imo) when it comes to transactions.
> >>>>> You might play a bit with the TransactionManagement and other stuff
> >>>>> probably.
> >>>>>
> >>>>> LieGrue,
> >>>>> strub
> >>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> >>>>> <rm...@gmail.com> wrote:
> >>>>>
> >>>>> Hmm deltaspike is a lib you can put in your app but if you really
> want
> >>>>> to get rid of it you can copy
> >>>>>
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> >>>>> Romain Manni-Bucau
> >>>>> Twitter: @rmannibucau
> >>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>> Github: https://github.com/rmannibucau
> >>>>>
> >>>>>
> >>>>>
> >>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >>>>>> Hi
> >>>>>>
> >>>>>> Thanks for the hint, however I'm not able to use Deltaspike but
> only the
> >>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
> >>>>>>
> >>>>>> How can I do this with OpenWebbeans only?
> >>>>>>
> >>>>>> Regards
> >>>>>> Lars-Fredrik
> >>>>>>
> >>>>>>
> >>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
> >>>>>> <rm...@gmail.com>
> >>>>>> wrote:
> >>>>>>>
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate
> your
> >>>>>>> executorService to do it and it should be fine:
> >>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
> >>>>>>> Romain Manni-Bucau
> >>>>>>> Twitter: @rmannibucau
> >>>>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>>>> Github: https://github.com/rmannibucau
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <
> itsmeden@gmail.com>:
> >>>>>>> > Hi
> >>>>>>> >
> >>>>>>> > If I within a thread wishes to start asynchronous "jobs" using
> the
> >>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait
> for
> >>>>>>> > the
> >>>>>>> > Future-result within that same thread I run into the following
> >>>>>>> > exception:
> >>>>>>> >
> >>>>>>> > "WebBeans context with scope type annotation @RequestScoped does
> not
> >>>>>>> > exist
> >>>>>>> > within current thread"
> >>>>>>> >
> >>>>>>> > which is understandable since the managed bean passed used in the
> >>>>>>> > Callable
> >>>>>>> > passed to ExecutorService.submit(...) contains injected beans
> iteself
> >>>>>>> > that
> >>>>>>> > are @RequestScoped.
> >>>>>>> >
> >>>>>>> > Is there any way around this? Suggestions on changing the design
> >>>>>>> > perhaps?
> >>>>>>> >
> >>>>>>> > Regards
> >>>>>>> > Lars-Fredrik Smedberg
> >>>>>>> >
> >>>>>>> >
> >>>>>>> > --
> >>>>>>> > 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.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> 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.
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >
> >
>
>
>
>


-- 
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.

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.
Concurrency utils is a completely different spec and IS broken as it does _not_ define it properly. But for @Asynchronous it's perfectly well defined in the spec.

I use this as thread starter for BatchEE and I've tested it in 
* TomEE
* WAS-8.0.0.6
* WAS-8.5.5.1
* JBossAS-7.0.3.Final
* latest WildFly

LieGrue,
strub


On Friday, 11 April 2014, 7:15, Romain Manni-Bucau <rm...@gmail.com> wrote:
 
Ok about the spec but propagation doesnt work for sure (it is a kind of issue for concurrency utilities)
>You are right for the config but i just realize i was really not clear (throw new TooLateException). If you sont configure the container, you can use a semaphore with 20 permits and the container block you to 10. So it is important to have a look too and it can be enough avoiding custom potentially buggy code.
>Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :
>
>
>>
>>> But not propagated in async pool..and not in ejb 3.1
>>Of course it is!
>>But you wont find this in the EJB spec - you need to look in the EE umbrella spec and the CDI spec ;)
>>
>>
>>> Ps: you can configure async pool or stateless pool
>>Yes, some container allow to configure this. But I'm pretty sure there is nothing in the spec which requires it. So I'd rather hack it myself.
>>
>>LieGrue,
>>strub
>>
>>
>>On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <rm...@gmail.com> wrote:
>>
>>Ps: you can configure async pool or stateless pool to limit concurrency depending the container...but a semaphore enforces it portably
>>>Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a écrit :
>>>
>>>But not propagated in async pool..and not in ejb 3.1
>>>>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
>>>>
>>>>
>>>>>
>>>>>Nope, not right.
>>>>>The CDI spec mandates that @RequestScoped is active for all EJB calls. And every subsequent invocation as well of course.
>>>>>
>>>>>LieGrue,
>>>>>strub
>>>>>
>>>>>
>>>>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <rm...@gmail.com> wrote:
>>>>>
>>>>>actually @Asynch doesn't mandates to start cdi contexts so request
>>>>>>scopes can or not be here but transactions are handled if you remove
>>>>>>transaction management.
>>>>>>Romain Manni-Bucau
>>>>>>Twitter: @rmannibucau
>>>>>>Blog: http://rmannibucau.wordpress.com/
>>>>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>Github: https://github.com/rmannibucau
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>>>>>>> Hi Lars-Fredrik!
>>>>>>>
>>>>>>> This is one of the rare situations where @Asynchronous is good
>>>>>>>
>>>>>>> @Stateless
>>>>>>> @TransactionManagement(TransactionManagementType.BEAN)
>>>>>>> public class ThreadExecutorEjb {
>>>>>>>
>>>>>>>     @Asynchronous
>>>>>>>     public void executeTask(Runnable work, Object config) {
>>>>>>>         work.run();
>>>>>>>     }
>>>>>>> }
>>>>>>>
>>>>>>> The problem with this approach is that WAS is _really_ picky (and far from
>>>>>>> the spec imo) when it comes to transactions.
>>>>>>> You might play a bit with the TransactionManagement and other stuff
>>>>>>> probably.
>>>>>>>
>>>>>>> LieGrue,
>>>>>>> strub
>>>>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>>>>>>> <rm...@gmail.com> wrote:
>>>>>>>
>>>>>>> Hmm deltaspike is a lib you can put in your app but if you really want
>>>>>>> to get rid of it you can copy
>>>>>>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>>>>>>> Romain Manni-Bucau
>>>>>>> Twitter: @rmannibucau
>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>>>>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>>>>>>
>>>>>>>> How can I do this with OpenWebbeans only?
>>>>>>>>
>>>>>>>> Regards
>>>>>>>> Lars-Fredrik
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>>>>>>>> <rm...@gmail.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>>>>>>>> executorService to do it and it should be fine:
>>>>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>>>>>>> Romain Manni-Bucau
>>>>>>>>> Twitter: @rmannibucau
>>>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>>>> > Hi
>>>>>>>>> >
>>>>>>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
>>>>>>>>> > the
>>>>>>>>> > Future-result within that same thread I run into the following
>>>>>>>>> > exception:
>>>>>>>>> >
>>>>>>>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>>>>>>>> > exist
>>>>>>>>> > within current thread"
>>>>>>>>> >
>>>>>>>>> > which is understandable since the managed bean passed used in the
>>>>>>>>> > Callable
>>>>>>>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>>>>>>>> > that
>>>>>>>>> > are @RequestScoped.
>>>>>>>>> >
>>>>>>>>> > Is there any way around this? Suggestions on changing the design
>>>>>>>>> > perhaps?
>>>>>>>>> >
>>>>>>>>> > Regards
>>>>>>>>> > Lars-Fredrik Smedberg
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > --
>>>>>>>>> > 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.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> 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.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
>>>
>>
>
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ok about the spec but propagation doesnt work for sure (it is a kind of
issue for concurrency utilities)

You are right for the config but i just realize i was really not clear
(throw new TooLateException). If you sont configure the container, you can
use a semaphore with 20 permits and the container block you to 10. So it is
important to have a look too and it can be enough avoiding custom
potentially buggy code.
Le 10 avr. 2014 22:40, "Mark Struberg" <st...@yahoo.de> a écrit :

>
>
> > But not propagated in async pool..and not in ejb 3.1
> Of course it is!
> But you wont find this in the EJB spec - you need to look in the EE
> umbrella spec and the CDI spec ;)
>
>
> > Ps: you can configure async pool or stateless pool
> Yes, some container allow to configure this. But I'm pretty sure there is
> nothing in the spec which requires it. So I'd rather hack it myself.
>
> LieGrue,
> strub
>
>
> On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Ps: you can configure async pool or stateless pool to limit concurrency
> depending the container...but a semaphore enforces it portably
> >Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a
> écrit :
> >
> >But not propagated in async pool..and not in ejb 3.1
> >>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
> >>
> >>
> >>>
> >>>Nope, not right.
> >>>The CDI spec mandates that @RequestScoped is active for all EJB calls.
> And every subsequent invocation as well of course.
> >>>
> >>>LieGrue,
> >>>strub
> >>>
> >>>
> >>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
> >>>
> >>>actually @Asynch doesn't mandates to start cdi contexts so request
> >>>>scopes can or not be here but transactions are handled if you remove
> >>>>transaction management.
> >>>>Romain Manni-Bucau
> >>>>Twitter: @rmannibucau
> >>>>Blog: http://rmannibucau.wordpress.com/
> >>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>Github: https://github.com/rmannibucau
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> >>>>> Hi Lars-Fredrik!
> >>>>>
> >>>>> This is one of the rare situations where @Asynchronous is good
> >>>>>
> >>>>> @Stateless
> >>>>> @TransactionManagement(TransactionManagementType.BEAN)
> >>>>> public class ThreadExecutorEjb {
> >>>>>
> >>>>>     @Asynchronous
> >>>>>     public void executeTask(Runnable work, Object config) {
> >>>>>         work.run();
> >>>>>     }
> >>>>> }
> >>>>>
> >>>>> The problem with this approach is that WAS is _really_ picky (and
> far from
> >>>>> the spec imo) when it comes to transactions.
> >>>>> You might play a bit with the TransactionManagement and other stuff
> >>>>> probably.
> >>>>>
> >>>>> LieGrue,
> >>>>> strub
> >>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> >>>>> <rm...@gmail.com> wrote:
> >>>>>
> >>>>> Hmm deltaspike is a lib you can put in your app but if you really
> want
> >>>>> to get rid of it you can copy
> >>>>>
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> >>>>> Romain Manni-Bucau
> >>>>> Twitter: @rmannibucau
> >>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>> Github: https://github.com/rmannibucau
> >>>>>
> >>>>>
> >>>>>
> >>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >>>>>> Hi
> >>>>>>
> >>>>>> Thanks for the hint, however I'm not able to use Deltaspike but
> only the
> >>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
> >>>>>>
> >>>>>> How can I do this with OpenWebbeans only?
> >>>>>>
> >>>>>> Regards
> >>>>>> Lars-Fredrik
> >>>>>>
> >>>>>>
> >>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
> >>>>>> <rm...@gmail.com>
> >>>>>> wrote:
> >>>>>>>
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate
> your
> >>>>>>> executorService to do it and it should be fine:
> >>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
> >>>>>>> Romain Manni-Bucau
> >>>>>>> Twitter: @rmannibucau
> >>>>>>> Blog: http://rmannibucau.wordpress.com/
> >>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>>>>> Github: https://github.com/rmannibucau
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <
> itsmeden@gmail.com>:
> >>>>>>> > Hi
> >>>>>>> >
> >>>>>>> > If I within a thread wishes to start asynchronous "jobs" using
> the
> >>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait
> for
> >>>>>>> > the
> >>>>>>> > Future-result within that same thread I run into the following
> >>>>>>> > exception:
> >>>>>>> >
> >>>>>>> > "WebBeans context with scope type annotation @RequestScoped does
> not
> >>>>>>> > exist
> >>>>>>> > within current thread"
> >>>>>>> >
> >>>>>>> > which is understandable since the managed bean passed used in the
> >>>>>>> > Callable
> >>>>>>> > passed to ExecutorService.submit(...) contains injected beans
> iteself
> >>>>>>> > that
> >>>>>>> > are @RequestScoped.
> >>>>>>> >
> >>>>>>> > Is there any way around this? Suggestions on changing the design
> >>>>>>> > perhaps?
> >>>>>>> >
> >>>>>>> > Regards
> >>>>>>> > Lars-Fredrik Smedberg
> >>>>>>> >
> >>>>>>> >
> >>>>>>> > --
> >>>>>>> > 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.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> 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.
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >
> >
>

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.

> But not propagated in async pool..and not in ejb 3.1
Of course it is!
But you wont find this in the EJB spec - you need to look in the EE umbrella spec and the CDI spec ;)


> Ps: you can configure async pool or stateless pool
Yes, some container allow to configure this. But I'm pretty sure there is nothing in the spec which requires it. So I'd rather hack it myself.

LieGrue,
strub


On Thursday, 10 April 2014, 23:18, Romain Manni-Bucau <rm...@gmail.com> wrote:

Ps: you can configure async pool or stateless pool to limit concurrency depending the container...but a semaphore enforces it portably
>Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a écrit :
>
>But not propagated in async pool..and not in ejb 3.1
>>Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
>>
>>
>>>
>>>Nope, not right.
>>>The CDI spec mandates that @RequestScoped is active for all EJB calls. And every subsequent invocation as well of course.
>>>
>>>LieGrue,
>>>strub
>>>
>>>
>>>On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <rm...@gmail.com> wrote:
>>>
>>>actually @Asynch doesn't mandates to start cdi contexts so request
>>>>scopes can or not be here but transactions are handled if you remove
>>>>transaction management.
>>>>Romain Manni-Bucau
>>>>Twitter: @rmannibucau
>>>>Blog: http://rmannibucau.wordpress.com/
>>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>Github: https://github.com/rmannibucau
>>>>
>>>>
>>>>
>>>>
>>>>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>>>>> Hi Lars-Fredrik!
>>>>>
>>>>> This is one of the rare situations where @Asynchronous is good
>>>>>
>>>>> @Stateless
>>>>> @TransactionManagement(TransactionManagementType.BEAN)
>>>>> public class ThreadExecutorEjb {
>>>>>
>>>>>     @Asynchronous
>>>>>     public void executeTask(Runnable work, Object config) {
>>>>>         work.run();
>>>>>     }
>>>>> }
>>>>>
>>>>> The problem with this approach is that WAS is _really_ picky (and far from
>>>>> the spec imo) when it comes to transactions.
>>>>> You might play a bit with the TransactionManagement and other stuff
>>>>> probably.
>>>>>
>>>>> LieGrue,
>>>>> strub
>>>>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>>>>> <rm...@gmail.com> wrote:
>>>>>
>>>>> Hmm deltaspike is a lib you can put in your app but if you really want
>>>>> to get rid of it you can copy
>>>>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>>>>> Romain Manni-Bucau
>>>>> Twitter: @rmannibucau
>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> Github: https://github.com/rmannibucau
>>>>>
>>>>>
>>>>>
>>>>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>> Hi
>>>>>>
>>>>>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>>>>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>>>>
>>>>>> How can I do this with OpenWebbeans only?
>>>>>>
>>>>>> Regards
>>>>>> Lars-Fredrik
>>>>>>
>>>>>>
>>>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>>>>>> <rm...@gmail.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>>>>>> executorService to do it and it should be fine:
>>>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>>>>> Romain Manni-Bucau
>>>>>>> Twitter: @rmannibucau
>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>>> > Hi
>>>>>>> >
>>>>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
>>>>>>> > the
>>>>>>> > Future-result within that same thread I run into the following
>>>>>>> > exception:
>>>>>>> >
>>>>>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>>>>>> > exist
>>>>>>> > within current thread"
>>>>>>> >
>>>>>>> > which is understandable since the managed bean passed used in the
>>>>>>> > Callable
>>>>>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>>>>>> > that
>>>>>>> > are @RequestScoped.
>>>>>>> >
>>>>>>> > Is there any way around this? Suggestions on changing the design
>>>>>>> > perhaps?
>>>>>>> >
>>>>>>> > Regards
>>>>>>> > Lars-Fredrik Smedberg
>>>>>>> >
>>>>>>> >
>>>>>>> > --
>>>>>>> > 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.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>>
>>>>>
>>>>
>>>>
>>>
>
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ps: you can configure async pool or stateless pool to limit concurrency
depending the container...but a semaphore enforces it portably
Le 10 avr. 2014 22:15, "Romain Manni-Bucau" <rm...@gmail.com> a
écrit :

> But not propagated in async pool..and not in ejb 3.1
> Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :
>
>>
>>
>> Nope, not right.
>> The CDI spec mandates that @RequestScoped is active for all EJB calls.
>> And every subsequent invocation as well of course.
>>
>> LieGrue,
>> strub
>>
>>
>> On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <
>> rmannibucau@gmail.com> wrote:
>>
>> actually @Asynch doesn't mandates to start cdi contexts so request
>> >scopes can or not be here but transactions are handled if you remove
>> >transaction management.
>> >Romain Manni-Bucau
>> >Twitter: @rmannibucau
>> >Blog: http://rmannibucau.wordpress.com/
>> >LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >Github: https://github.com/rmannibucau
>> >
>> >
>> >
>> >
>> >2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>> >> Hi Lars-Fredrik!
>> >>
>> >> This is one of the rare situations where @Asynchronous is good
>> >>
>> >> @Stateless
>> >> @TransactionManagement(TransactionManagementType.BEAN)
>> >> public class ThreadExecutorEjb {
>> >>
>> >>     @Asynchronous
>> >>     public void executeTask(Runnable work, Object config) {
>> >>         work.run();
>> >>     }
>> >> }
>> >>
>> >> The problem with this approach is that WAS is _really_ picky (and far
>> from
>> >> the spec imo) when it comes to transactions.
>> >> You might play a bit with the TransactionManagement and other stuff
>> >> probably.
>> >>
>> >> LieGrue,
>> >> strub
>> >> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>> >> <rm...@gmail.com> wrote:
>> >>
>> >> Hmm deltaspike is a lib you can put in your app but if you really want
>> >> to get rid of it you can copy
>> >>
>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >>
>> >> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >>> Hi
>> >>>
>> >>> Thanks for the hint, however I'm not able to use Deltaspike but only
>> the
>> >>> OpenWebbeans included with WebSphere 8.5.5.x...
>> >>>
>> >>> How can I do this with OpenWebbeans only?
>> >>>
>> >>> Regards
>> >>> Lars-Fredrik
>> >>>
>> >>>
>> >>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>> >>> <rm...@gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> Hi
>> >>>>
>> >>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>> >>>> executorService to do it and it should be fine:
>> >>>> http://openwebbeans.apache.org/testing_cdictrl.html
>> >>>> Romain Manni-Bucau
>> >>>> Twitter: @rmannibucau
>> >>>> Blog: http://rmannibucau.wordpress.com/
>> >>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >>>> Github: https://github.com/rmannibucau
>> >>>>
>> >>>>
>> >>>>
>> >>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
>> >:
>> >>>> > Hi
>> >>>> >
>> >>>> > If I within a thread wishes to start asynchronous "jobs" using the
>> >>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait
>> for
>> >>>> > the
>> >>>> > Future-result within that same thread I run into the following
>> >>>> > exception:
>> >>>> >
>> >>>> > "WebBeans context with scope type annotation @RequestScoped does
>> not
>> >>>> > exist
>> >>>> > within current thread"
>> >>>> >
>> >>>> > which is understandable since the managed bean passed used in the
>> >>>> > Callable
>> >>>> > passed to ExecutorService.submit(...) contains injected beans
>> iteself
>> >>>> > that
>> >>>> > are @RequestScoped.
>> >>>> >
>> >>>> > Is there any way around this? Suggestions on changing the design
>> >>>> > perhaps?
>> >>>> >
>> >>>> > Regards
>> >>>> > Lars-Fredrik Smedberg
>> >>>> >
>> >>>> >
>> >>>> > --
>> >>>> > 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.
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> 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.
>> >>
>> >>
>> >
>> >
>>
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
But not propagated in async pool..and not in ejb 3.1
Le 10 avr. 2014 20:54, "Mark Struberg" <st...@yahoo.de> a écrit :

>
>
> Nope, not right.
> The CDI spec mandates that @RequestScoped is active for all EJB calls. And
> every subsequent invocation as well of course.
>
> LieGrue,
> strub
>
>
> On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> actually @Asynch doesn't mandates to start cdi contexts so request
> >scopes can or not be here but transactions are handled if you remove
> >transaction management.
> >Romain Manni-Bucau
> >Twitter: @rmannibucau
> >Blog: http://rmannibucau.wordpress.com/
> >LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >Github: https://github.com/rmannibucau
> >
> >
> >
> >
> >2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> >> Hi Lars-Fredrik!
> >>
> >> This is one of the rare situations where @Asynchronous is good
> >>
> >> @Stateless
> >> @TransactionManagement(TransactionManagementType.BEAN)
> >> public class ThreadExecutorEjb {
> >>
> >>     @Asynchronous
> >>     public void executeTask(Runnable work, Object config) {
> >>         work.run();
> >>     }
> >> }
> >>
> >> The problem with this approach is that WAS is _really_ picky (and far
> from
> >> the spec imo) when it comes to transactions.
> >> You might play a bit with the TransactionManagement and other stuff
> >> probably.
> >>
> >> LieGrue,
> >> strub
> >> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> >> <rm...@gmail.com> wrote:
> >>
> >> Hmm deltaspike is a lib you can put in your app but if you really want
> >> to get rid of it you can copy
> >>
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >>
> >> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >>> Hi
> >>>
> >>> Thanks for the hint, however I'm not able to use Deltaspike but only
> the
> >>> OpenWebbeans included with WebSphere 8.5.5.x...
> >>>
> >>> How can I do this with OpenWebbeans only?
> >>>
> >>> Regards
> >>> Lars-Fredrik
> >>>
> >>>
> >>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
> >>> <rm...@gmail.com>
> >>> wrote:
> >>>>
> >>>> Hi
> >>>>
> >>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
> >>>> executorService to do it and it should be fine:
> >>>> http://openwebbeans.apache.org/testing_cdictrl.html
> >>>> Romain Manni-Bucau
> >>>> Twitter: @rmannibucau
> >>>> Blog: http://rmannibucau.wordpress.com/
> >>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >>>> Github: https://github.com/rmannibucau
> >>>>
> >>>>
> >>>>
> >>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >>>> > Hi
> >>>> >
> >>>> > If I within a thread wishes to start asynchronous "jobs" using the
> >>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
> >>>> > the
> >>>> > Future-result within that same thread I run into the following
> >>>> > exception:
> >>>> >
> >>>> > "WebBeans context with scope type annotation @RequestScoped does not
> >>>> > exist
> >>>> > within current thread"
> >>>> >
> >>>> > which is understandable since the managed bean passed used in the
> >>>> > Callable
> >>>> > passed to ExecutorService.submit(...) contains injected beans
> iteself
> >>>> > that
> >>>> > are @RequestScoped.
> >>>> >
> >>>> > Is there any way around this? Suggestions on changing the design
> >>>> > perhaps?
> >>>> >
> >>>> > Regards
> >>>> > Lars-Fredrik Smedberg
> >>>> >
> >>>> >
> >>>> > --
> >>>> > 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.
> >>>
> >>>
> >>>
> >>>
> >>> --
> >>> 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.
> >>
> >>
> >
> >
>

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.

Nope, not right. 
The CDI spec mandates that @RequestScoped is active for all EJB calls. And every subsequent invocation as well of course.

LieGrue,
strub


On Thursday, 10 April 2014, 17:52, Romain Manni-Bucau <rm...@gmail.com> wrote:

actually @Asynch doesn't mandates to start cdi contexts so request
>scopes can or not be here but transactions are handled if you remove
>transaction management.
>Romain Manni-Bucau
>Twitter: @rmannibucau
>Blog: http://rmannibucau.wordpress.com/
>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>Github: https://github.com/rmannibucau
>
>
>
>
>2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
>> Hi Lars-Fredrik!
>>
>> This is one of the rare situations where @Asynchronous is good
>>
>> @Stateless
>> @TransactionManagement(TransactionManagementType.BEAN)
>> public class ThreadExecutorEjb {
>>
>>     @Asynchronous
>>     public void executeTask(Runnable work, Object config) {
>>         work.run();
>>     }
>> }
>>
>> The problem with this approach is that WAS is _really_ picky (and far from
>> the spec imo) when it comes to transactions.
>> You might play a bit with the TransactionManagement and other stuff
>> probably.
>>
>> LieGrue,
>> strub
>> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
>> <rm...@gmail.com> wrote:
>>
>> Hmm deltaspike is a lib you can put in your app but if you really want
>> to get rid of it you can copy
>> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>> Hi
>>>
>>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>
>>> How can I do this with OpenWebbeans only?
>>>
>>> Regards
>>> Lars-Fredrik
>>>
>>>
>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>>> <rm...@gmail.com>
>>> wrote:
>>>>
>>>> Hi
>>>>
>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>>> executorService to do it and it should be fine:
>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>> Romain Manni-Bucau
>>>> Twitter: @rmannibucau
>>>> Blog: http://rmannibucau.wordpress.com/
>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> Github: https://github.com/rmannibucau
>>>>
>>>>
>>>>
>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>> > Hi
>>>> >
>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
>>>> > the
>>>> > Future-result within that same thread I run into the following
>>>> > exception:
>>>> >
>>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>>> > exist
>>>> > within current thread"
>>>> >
>>>> > which is understandable since the managed bean passed used in the
>>>> > Callable
>>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>>> > that
>>>> > are @RequestScoped.
>>>> >
>>>> > Is there any way around this? Suggestions on changing the design
>>>> > perhaps?
>>>> >
>>>> > Regards
>>>> > Lars-Fredrik Smedberg
>>>> >
>>>> >
>>>> > --
>>>> > 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.
>>>
>>>
>>>
>>>
>>> --
>>> 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.
>>
>>
>
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
actually @Asynch doesn't mandates to start cdi contexts so request
scopes can or not be here but transactions are handled if you remove
transaction management.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-10 17:49 GMT+02:00 Mark Struberg <st...@yahoo.de>:
> Hi Lars-Fredrik!
>
> This is one of the rare situations where @Asynchronous is good
>
> @Stateless
> @TransactionManagement(TransactionManagementType.BEAN)
> public class ThreadExecutorEjb {
>
>     @Asynchronous
>     public void executeTask(Runnable work, Object config) {
>         work.run();
>     }
> }
>
> The problem with this approach is that WAS is _really_ picky (and far from
> the spec imo) when it comes to transactions.
> You might play a bit with the TransactionManagement and other stuff
> probably.
>
> LieGrue,
> strub
> On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau
> <rm...@gmail.com> wrote:
>
> Hmm deltaspike is a lib you can put in your app but if you really want
> to get rid of it you can copy
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> Hi
>>
>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>> OpenWebbeans included with WebSphere 8.5.5.x...
>>
>> How can I do this with OpenWebbeans only?
>>
>> Regards
>> Lars-Fredrik
>>
>>
>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
>> <rm...@gmail.com>
>> wrote:
>>>
>>> Hi
>>>
>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>> executorService to do it and it should be fine:
>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>> Romain Manni-Bucau
>>> Twitter: @rmannibucau
>>> Blog: http://rmannibucau.wordpress.com/
>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> Github: https://github.com/rmannibucau
>>>
>>>
>>>
>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>> > Hi
>>> >
>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
>>> > the
>>> > Future-result within that same thread I run into the following
>>> > exception:
>>> >
>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>> > exist
>>> > within current thread"
>>> >
>>> > which is understandable since the managed bean passed used in the
>>> > Callable
>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>> > that
>>> > are @RequestScoped.
>>> >
>>> > Is there any way around this? Suggestions on changing the design
>>> > perhaps?
>>> >
>>> > Regards
>>> > Lars-Fredrik Smedberg
>>> >
>>> >
>>> > --
>>> > 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.
>>
>>
>>
>>
>> --
>> 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.
>
>

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.
The TransactionManagement etc is only needed if you use manually controlled TX inside of your thread.

Regarding thread limiting. There is no default functionality for this in EJB afaik. But you can easily have an AtomicInteger and semaphores to implement the locking yourself.

LieGrue,
strub


On Thursday, 10 April 2014, 22:29, Lars-Fredrik Smedberg <it...@gmail.com> wrote:
 
Hi Mark
>
>
>In what scenarios would I need to configure the @TransactionManagement would you say? I'm looking into running several SOAP calls in parallell, the work that makes the call and receive the answer needs injected beans (which is why I ran into my problem in the first place).
>
>
>Using your example I would assume that I inject the EJB once and then make multiple calls to executeTask to be able to execute multiple "work" Runnables concurenty?
>
>
>Do you have any suggestion on how to limit the total number of "work" Runnables that run in parallell by all threads (similar to using an fixed size thread pool ExecutionService).
>
>
>Thanks for helping
>
>
>Regards
>Lars-Fredrik
>
>
>
>
>
>
>
>On Thu, Apr 10, 2014 at 5:49 PM, Mark Struberg <st...@yahoo.de> wrote:
>
>Hi Lars-Fredrik!
>>
>>This is one of the rare situations where @Asynchronous is good
>>
>>@Stateless
>>@TransactionManagement(TransactionManagementType.BEAN)
>>public class ThreadExecutorEjb {
>>    
>>    @Asynchronous
>>    public void executeTask(Runnable work, Object config) {
>>        work.run();
>>    }
>>}
>>
>>
>>The problem with this approach is that WAS is _really_ picky (and far from the spec imo) when it comes to transactions. 
>>
>>You might play a bit with the TransactionManagement and other stuff probably.
>>
>>
>>LieGrue,
>>strub
>>
>>On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau <rm...@gmail.com> wrote:
>> 
>>Hmm deltaspike is a lib you can put in your app but if you really want
>>>to get rid of it you can copy
>>>https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>>>Romain Manni-Bucau
>>>Twitter: @rmannibucau
>>>Blog: http://rmannibucau.wordpress.com/
>>>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>Github: https://github.com/rmannibucau
>>>
>>>
>>>
>>>
>>>2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>> Hi
>>>>
>>>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>>>> OpenWebbeans included with WebSphere 8.5.5.x...
>>>>
>>>> How can I do this with OpenWebbeans only?
>>>>
>>>> Regards
>>>> Lars-Fredrik
>>>>
>>>>
>>>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau <rm...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi
>>>>>
>>>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>>>> executorService to do it and it should be fine:
>>>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>>>> Romain Manni-Bucau
>>>>> Twitter: @rmannibucau
>>>>>
 Blog: http://rmannibucau.wordpress.com/
>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> Github: https://github.com/rmannibucau
>>>>>
>>>>>
>>>>>
>>>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>> > Hi
>>>>> >
>>>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
>>>>> >
 Future-result within that same thread I run into the following
>>>>> > exception:
>>>>> >
>>>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>>>> > exist
>>>>> > within current thread"
>>>>> >
>>>>> > which is understandable since the managed bean passed used in the
>>>>> > Callable
>>>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>>>> > that
>>>>> > are @RequestScoped.
>>>>> >
>>>>> > Is there any way around this? Suggestions on changing the design
>>>>> > perhaps?
>>>>> >
>>>>> > Regards
>>>>> > Lars-Fredrik Smedberg
>>>>> >
>>>>> >
>>>>> > --
>>>>> > 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.
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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.
>>>
>>>
>
>
>
>-- 
>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. 
>
>

Re: Design - CDI and worker threads

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi Mark

In what scenarios would I need to configure the @TransactionManagement
would you say? I'm looking into running several SOAP calls in parallell,
the work that makes the call and receive the answer needs injected beans
(which is why I ran into my problem in the first place).

Using your example I would assume that I inject the EJB once and then make
multiple calls to executeTask to be able to execute multiple "work"
Runnables concurenty?

Do you have any suggestion on how to limit the total number of "work"
Runnables that run in parallell by all threads (similar to using an fixed
size thread pool ExecutionService).

Thanks for helping

Regards
Lars-Fredrik




On Thu, Apr 10, 2014 at 5:49 PM, Mark Struberg <st...@yahoo.de> wrote:

> Hi Lars-Fredrik!
>
> This is one of the rare situations where @Asynchronous is good
>
> @Stateless
> @TransactionManagement(TransactionManagementType.BEAN)
> public class ThreadExecutorEjb {
>
>     @Asynchronous
>     public void executeTask(Runnable work, Object config) {
>         work.run();
>     }
> }
>
> The problem with this approach is that WAS is _really_ picky (and far from
> the spec imo) when it comes to transactions.
> You might play a bit with the TransactionManagement and other stuff
> probably.
>
> LieGrue,
> strub
>   On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau <
> rmannibucau@gmail.com> wrote:
>
> Hmm deltaspike is a lib you can put in your app but if you really want
> to get rid of it you can copy
>
> https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > Hi
> >
> > Thanks for the hint, however I'm not able to use Deltaspike but only the
> > OpenWebbeans included with WebSphere 8.5.5.x...
> >
> > How can I do this with OpenWebbeans only?
> >
> > Regards
> > Lars-Fredrik
> >
> >
> > On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >>
> >> Hi
> >>
> >> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
> >> executorService to do it and it should be fine:
> >> http://openwebbeans.apache.org/testing_cdictrl.html
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >>
> >> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > Hi
> >> >
> >> > If I within a thread wishes to start asynchronous "jobs" using the
> >> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for
> the
> >> > Future-result within that same thread I run into the following
> >> > exception:
> >> >
> >> > "WebBeans context with scope type annotation @RequestScoped does not
> >> > exist
> >> > within current thread"
> >> >
> >> > which is understandable since the managed bean passed used in the
> >> > Callable
> >> > passed to ExecutorService.submit(...) contains injected beans iteself
> >> > that
> >> > are @RequestScoped.
> >> >
> >> > Is there any way around this? Suggestions on changing the design
> >> > perhaps?
> >> >
> >> > Regards
> >> > Lars-Fredrik Smedberg
> >> >
> >> >
> >> > --
> >> > 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.
> >
> >
> >
> >
> > --
> > 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.
>
>
>


-- 
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.

Re: Design - CDI and worker threads

Posted by Mark Struberg <st...@yahoo.de>.
Hi Lars-Fredrik!

This is one of the rare situations where @Asynchronous is good

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class ThreadExecutorEjb {
    
    @Asynchronous
    public void executeTask(Runnable work, Object config) {
        work.run();
    }
}


The problem with this approach is that WAS is _really_ picky (and far from the spec imo) when it comes to transactions. 

You might play a bit with the TransactionManagement and other stuff probably.

LieGrue,
strub

On Thursday, 10 April 2014, 16:21, Romain Manni-Bucau <rm...@gmail.com> wrote:
 
Hmm deltaspike is a lib you can put in your app but if you really want
>to get rid of it you can copy
>https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
>Romain Manni-Bucau
>Twitter: @rmannibucau
>Blog: http://rmannibucau.wordpress.com/
>LinkedIn: http://fr.linkedin.com/in/rmannibucau
>Github: https://github.com/rmannibucau
>
>
>
>
>2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> Hi
>>
>> Thanks for the hint, however I'm not able to use Deltaspike but only the
>> OpenWebbeans included with WebSphere 8.5.5.x...
>>
>> How can I do this with OpenWebbeans only?
>>
>> Regards
>> Lars-Fredrik
>>
>>
>> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau <rm...@gmail.com>
>> wrote:
>>>
>>> Hi
>>>
>>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>>> executorService to do it and it should be fine:
>>> http://openwebbeans.apache.org/testing_cdictrl.html
>>> Romain Manni-Bucau
>>> Twitter: @rmannibucau
>>> Blog: http://rmannibucau.wordpress.com/
>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> Github: https://github.com/rmannibucau
>>>
>>>
>>>
>>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>> > Hi
>>> >
>>> > If I within a thread wishes to start asynchronous "jobs" using the
>>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
>>> > Future-result within that same thread I run into the following
>>> > exception:
>>> >
>>> > "WebBeans context with scope type annotation @RequestScoped does not
>>> > exist
>>> > within current thread"
>>> >
>>> > which is understandable since the managed bean passed used in the
>>> > Callable
>>> > passed to ExecutorService.submit(...) contains injected beans iteself
>>> > that
>>> > are @RequestScoped.
>>> >
>>> > Is there any way around this? Suggestions on changing the design
>>> > perhaps?
>>> >
>>> > Regards
>>> > Lars-Fredrik Smedberg
>>> >
>>> >
>>> > --
>>> > 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.
>>
>>
>>
>>
>> --
>> 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.
>
>

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hmm deltaspike is a lib you can put in your app but if you really want
to get rid of it you can copy
https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java;h=9e8ba98d46abc3843e8e5b872c882989a98fe16a;hb=HEAD
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-10 15:52 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> Hi
>
> Thanks for the hint, however I'm not able to use Deltaspike but only the
> OpenWebbeans included with WebSphere 8.5.5.x...
>
> How can I do this with OpenWebbeans only?
>
> Regards
> Lars-Fredrik
>
>
> On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>>
>> Hi
>>
>> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
>> executorService to do it and it should be fine:
>> http://openwebbeans.apache.org/testing_cdictrl.html
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > Hi
>> >
>> > If I within a thread wishes to start asynchronous "jobs" using the
>> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
>> > Future-result within that same thread I run into the following
>> > exception:
>> >
>> > "WebBeans context with scope type annotation @RequestScoped does not
>> > exist
>> > within current thread"
>> >
>> > which is understandable since the managed bean passed used in the
>> > Callable
>> > passed to ExecutorService.submit(...) contains injected beans iteself
>> > that
>> > are @RequestScoped.
>> >
>> > Is there any way around this? Suggestions on changing the design
>> > perhaps?
>> >
>> > Regards
>> > Lars-Fredrik Smedberg
>> >
>> >
>> > --
>> > 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.
>
>
>
>
> --
> 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.

Re: Design - CDI and worker threads

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi

Thanks for the hint, however I'm not able to use Deltaspike but only the
OpenWebbeans included with WebSphere 8.5.5.x...

How can I do this with OpenWebbeans only?

Regards
Lars-Fredrik


On Thu, Apr 10, 2014 at 3:47 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Hi
>
> with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
> executorService to do it and it should be fine:
> http://openwebbeans.apache.org/testing_cdictrl.html
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > Hi
> >
> > If I within a thread wishes to start asynchronous "jobs" using the
> > ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
> > Future-result within that same thread I run into the following exception:
> >
> > "WebBeans context with scope type annotation @RequestScoped does not
> exist
> > within current thread"
> >
> > which is understandable since the managed bean passed used in the
> Callable
> > passed to ExecutorService.submit(...) contains injected beans iteself
> that
> > are @RequestScoped.
> >
> > Is there any way around this? Suggestions on changing the design perhaps?
> >
> > Regards
> > Lars-Fredrik Smedberg
> >
> >
> > --
> > 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.
>



-- 
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.

Re: Design - CDI and worker threads

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

with CdiCtrl of deltaspike you can start/stop contexts. Decorate your
executorService to do it and it should be fine:
http://openwebbeans.apache.org/testing_cdictrl.html
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-04-10 15:37 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> Hi
>
> If I within a thread wishes to start asynchronous "jobs" using the
> ExecutorService (and Executors.newFixedThreadPool(...)) and wait for the
> Future-result within that same thread I run into the following exception:
>
> "WebBeans context with scope type annotation @RequestScoped does not exist
> within current thread"
>
> which is understandable since the managed bean passed used in the Callable
> passed to ExecutorService.submit(...) contains injected beans iteself that
> are @RequestScoped.
>
> Is there any way around this? Suggestions on changing the design perhaps?
>
> Regards
> Lars-Fredrik Smedberg
>
>
> --
> 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.