You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Lars-Fredrik Smedberg <it...@gmail.com> on 2014/09/01 16:27:09 UTC

Re: Questions on EJB, CDI and concurrency

Hi Romain

A follow up question. What will the difference between a @Singleton EJB and
a @Statefull @ApplicationScoped EJB be? Is it only the fact that the latter
will have a CDI-proxy in fron of the EJB-proxy but function wise they will
work the same?

Regards
Lars-Fredrik


On Tue, Aug 26, 2014 at 4:50 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hi
>
> 2014-08-26 16:45 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > Hi
> >
> > I have a few questions on EJB, CDI and Concurrency when I read
> > http://tomee.apache.org/examples-trunk/access-timeout/README.html, I
> read
> >
> > - Concurrent access to a @Stateful bean is serialized by the container.
> >
> > I also understand that I can annotate the EJBs with any of the CDI-scopes
> > (in my case I'm interested in @RequestScoped, @SessionScoped and
> > @ApplicationScoped).
> >
> > Questions:
> >
> > 1. If I annotate the @Stateful bean with @RequestScoped I assume that I
> get
> > a separate bean instance for each call? Correct?
>
> yes
>
> > 2. If I annotate the @Stateful bean with @SessionScoped I assume that I
> per
> > sesion get a separate bean instance that allows concurrent calls withing
> > that particular session without wait? Correct?
>
> you get one instance by session and calls are serialized if needed to
> ensure thread safety
>
> > 3. If I annotate the @Stateful bean with @ApplicationScoped I assume
> that I
> > per application get one bean instance that allows concurrent calls
> without
> > wait? Correct?
> >
>
> same as before, thread safety is ensured
>
> > The reason I ask is that as far as I understand CDI does not have any
> > concurrency management but the EJB has. What will be the case when doing
> as
> > above?
> >
> > Please help me get some in-depth understanding on this.
> >
>
> for @AppScoped => look @javax.ejb.Singleton and @Lock which is surely
> better
>
> > Thanks
> > 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: Questions on EJB, CDI and concurrency

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
agree... seems weird


On Mon, Sep 1, 2014 at 4:41 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> yep
>
> stateful scope is bound to client scope, having an appscoped stateful
> is quite weird from my point of view ;)
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-01 16:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > So basically if I instead use @Singleton I have the possibility to use
> bean
> > managed concurrency as well as @Lock(READ)... ?
> >
> > Regards
> > Lars-Fredrik
> >
> >
> > On Mon, Sep 1, 2014 at 4:31 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> >> stateful appscoped = @singleton @lock(write)
> >>
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >> 2014-09-01 16:27 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > Hi Romain
> >> >
> >> > A follow up question. What will the difference between a @Singleton
> EJB
> >> and
> >> > a @Statefull @ApplicationScoped EJB be? Is it only the fact that the
> >> latter
> >> > will have a CDI-proxy in fron of the EJB-proxy but function wise they
> >> will
> >> > work the same?
> >> >
> >> > Regards
> >> > Lars-Fredrik
> >> >
> >> >
> >> > On Tue, Aug 26, 2014 at 4:50 PM, Romain Manni-Bucau <
> >> rmannibucau@gmail.com>
> >> > wrote:
> >> >
> >> >> Hi
> >> >>
> >> >> 2014-08-26 16:45 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >> >> > Hi
> >> >> >
> >> >> > I have a few questions on EJB, CDI and Concurrency when I read
> >> >> > http://tomee.apache.org/examples-trunk/access-timeout/README.html,
> I
> >> >> read
> >> >> >
> >> >> > - Concurrent access to a @Stateful bean is serialized by the
> >> container.
> >> >> >
> >> >> > I also understand that I can annotate the EJBs with any of the
> >> CDI-scopes
> >> >> > (in my case I'm interested in @RequestScoped, @SessionScoped and
> >> >> > @ApplicationScoped).
> >> >> >
> >> >> > Questions:
> >> >> >
> >> >> > 1. If I annotate the @Stateful bean with @RequestScoped I assume
> that
> >> I
> >> >> get
> >> >> > a separate bean instance for each call? Correct?
> >> >>
> >> >> yes
> >> >>
> >> >> > 2. If I annotate the @Stateful bean with @SessionScoped I assume
> that
> >> I
> >> >> per
> >> >> > sesion get a separate bean instance that allows concurrent calls
> >> withing
> >> >> > that particular session without wait? Correct?
> >> >>
> >> >> you get one instance by session and calls are serialized if needed to
> >> >> ensure thread safety
> >> >>
> >> >> > 3. If I annotate the @Stateful bean with @ApplicationScoped I
> assume
> >> >> that I
> >> >> > per application get one bean instance that allows concurrent calls
> >> >> without
> >> >> > wait? Correct?
> >> >> >
> >> >>
> >> >> same as before, thread safety is ensured
> >> >>
> >> >> > The reason I ask is that as far as I understand CDI does not have
> any
> >> >> > concurrency management but the EJB has. What will be the case when
> >> doing
> >> >> as
> >> >> > above?
> >> >> >
> >> >> > Please help me get some in-depth understanding on this.
> >> >> >
> >> >>
> >> >> for @AppScoped => look @javax.ejb.Singleton and @Lock which is surely
> >> >> better
> >> >>
> >> >> > Thanks
> >> >> > 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: Questions on EJB, CDI and concurrency

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

stateful scope is bound to client scope, having an appscoped stateful
is quite weird from my point of view ;)


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-09-01 16:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> So basically if I instead use @Singleton I have the possibility to use bean
> managed concurrency as well as @Lock(READ)... ?
>
> Regards
> Lars-Fredrik
>
>
> On Mon, Sep 1, 2014 at 4:31 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
>> stateful appscoped = @singleton @lock(write)
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-01 16:27 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > Hi Romain
>> >
>> > A follow up question. What will the difference between a @Singleton EJB
>> and
>> > a @Statefull @ApplicationScoped EJB be? Is it only the fact that the
>> latter
>> > will have a CDI-proxy in fron of the EJB-proxy but function wise they
>> will
>> > work the same?
>> >
>> > Regards
>> > Lars-Fredrik
>> >
>> >
>> > On Tue, Aug 26, 2014 at 4:50 PM, Romain Manni-Bucau <
>> rmannibucau@gmail.com>
>> > wrote:
>> >
>> >> Hi
>> >>
>> >> 2014-08-26 16:45 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >> > Hi
>> >> >
>> >> > I have a few questions on EJB, CDI and Concurrency when I read
>> >> > http://tomee.apache.org/examples-trunk/access-timeout/README.html, I
>> >> read
>> >> >
>> >> > - Concurrent access to a @Stateful bean is serialized by the
>> container.
>> >> >
>> >> > I also understand that I can annotate the EJBs with any of the
>> CDI-scopes
>> >> > (in my case I'm interested in @RequestScoped, @SessionScoped and
>> >> > @ApplicationScoped).
>> >> >
>> >> > Questions:
>> >> >
>> >> > 1. If I annotate the @Stateful bean with @RequestScoped I assume that
>> I
>> >> get
>> >> > a separate bean instance for each call? Correct?
>> >>
>> >> yes
>> >>
>> >> > 2. If I annotate the @Stateful bean with @SessionScoped I assume that
>> I
>> >> per
>> >> > sesion get a separate bean instance that allows concurrent calls
>> withing
>> >> > that particular session without wait? Correct?
>> >>
>> >> you get one instance by session and calls are serialized if needed to
>> >> ensure thread safety
>> >>
>> >> > 3. If I annotate the @Stateful bean with @ApplicationScoped I assume
>> >> that I
>> >> > per application get one bean instance that allows concurrent calls
>> >> without
>> >> > wait? Correct?
>> >> >
>> >>
>> >> same as before, thread safety is ensured
>> >>
>> >> > The reason I ask is that as far as I understand CDI does not have any
>> >> > concurrency management but the EJB has. What will be the case when
>> doing
>> >> as
>> >> > above?
>> >> >
>> >> > Please help me get some in-depth understanding on this.
>> >> >
>> >>
>> >> for @AppScoped => look @javax.ejb.Singleton and @Lock which is surely
>> >> better
>> >>
>> >> > Thanks
>> >> > 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: Questions on EJB, CDI and concurrency

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
So basically if I instead use @Singleton I have the possibility to use bean
managed concurrency as well as @Lock(READ)... ?

Regards
Lars-Fredrik


On Mon, Sep 1, 2014 at 4:31 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> stateful appscoped = @singleton @lock(write)
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-01 16:27 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > Hi Romain
> >
> > A follow up question. What will the difference between a @Singleton EJB
> and
> > a @Statefull @ApplicationScoped EJB be? Is it only the fact that the
> latter
> > will have a CDI-proxy in fron of the EJB-proxy but function wise they
> will
> > work the same?
> >
> > Regards
> > Lars-Fredrik
> >
> >
> > On Tue, Aug 26, 2014 at 4:50 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> >> Hi
> >>
> >> 2014-08-26 16:45 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > Hi
> >> >
> >> > I have a few questions on EJB, CDI and Concurrency when I read
> >> > http://tomee.apache.org/examples-trunk/access-timeout/README.html, I
> >> read
> >> >
> >> > - Concurrent access to a @Stateful bean is serialized by the
> container.
> >> >
> >> > I also understand that I can annotate the EJBs with any of the
> CDI-scopes
> >> > (in my case I'm interested in @RequestScoped, @SessionScoped and
> >> > @ApplicationScoped).
> >> >
> >> > Questions:
> >> >
> >> > 1. If I annotate the @Stateful bean with @RequestScoped I assume that
> I
> >> get
> >> > a separate bean instance for each call? Correct?
> >>
> >> yes
> >>
> >> > 2. If I annotate the @Stateful bean with @SessionScoped I assume that
> I
> >> per
> >> > sesion get a separate bean instance that allows concurrent calls
> withing
> >> > that particular session without wait? Correct?
> >>
> >> you get one instance by session and calls are serialized if needed to
> >> ensure thread safety
> >>
> >> > 3. If I annotate the @Stateful bean with @ApplicationScoped I assume
> >> that I
> >> > per application get one bean instance that allows concurrent calls
> >> without
> >> > wait? Correct?
> >> >
> >>
> >> same as before, thread safety is ensured
> >>
> >> > The reason I ask is that as far as I understand CDI does not have any
> >> > concurrency management but the EJB has. What will be the case when
> doing
> >> as
> >> > above?
> >> >
> >> > Please help me get some in-depth understanding on this.
> >> >
> >>
> >> for @AppScoped => look @javax.ejb.Singleton and @Lock which is surely
> >> better
> >>
> >> > Thanks
> >> > 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: Questions on EJB, CDI and concurrency

Posted by Romain Manni-Bucau <rm...@gmail.com>.
stateful appscoped = @singleton @lock(write)


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-09-01 16:27 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> Hi Romain
>
> A follow up question. What will the difference between a @Singleton EJB and
> a @Statefull @ApplicationScoped EJB be? Is it only the fact that the latter
> will have a CDI-proxy in fron of the EJB-proxy but function wise they will
> work the same?
>
> Regards
> Lars-Fredrik
>
>
> On Tue, Aug 26, 2014 at 4:50 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
>> Hi
>>
>> 2014-08-26 16:45 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > Hi
>> >
>> > I have a few questions on EJB, CDI and Concurrency when I read
>> > http://tomee.apache.org/examples-trunk/access-timeout/README.html, I
>> read
>> >
>> > - Concurrent access to a @Stateful bean is serialized by the container.
>> >
>> > I also understand that I can annotate the EJBs with any of the CDI-scopes
>> > (in my case I'm interested in @RequestScoped, @SessionScoped and
>> > @ApplicationScoped).
>> >
>> > Questions:
>> >
>> > 1. If I annotate the @Stateful bean with @RequestScoped I assume that I
>> get
>> > a separate bean instance for each call? Correct?
>>
>> yes
>>
>> > 2. If I annotate the @Stateful bean with @SessionScoped I assume that I
>> per
>> > sesion get a separate bean instance that allows concurrent calls withing
>> > that particular session without wait? Correct?
>>
>> you get one instance by session and calls are serialized if needed to
>> ensure thread safety
>>
>> > 3. If I annotate the @Stateful bean with @ApplicationScoped I assume
>> that I
>> > per application get one bean instance that allows concurrent calls
>> without
>> > wait? Correct?
>> >
>>
>> same as before, thread safety is ensured
>>
>> > The reason I ask is that as far as I understand CDI does not have any
>> > concurrency management but the EJB has. What will be the case when doing
>> as
>> > above?
>> >
>> > Please help me get some in-depth understanding on this.
>> >
>>
>> for @AppScoped => look @javax.ejb.Singleton and @Lock which is surely
>> better
>>
>> > Thanks
>> > 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.