About Question enthuware.oce-ejbd.v6.2.391 :

Moderator: admin

Post Reply
deadlock_gr
Posts: 54
Joined: Tue Apr 19, 2011 10:32 am
Contact:

About Question enthuware.oce-ejbd.v6.2.391 :

Post by deadlock_gr »

What if 10 instances of the Stateless EJB are pooled? Won't 10 interceptors be instantiated for them?

deadlock_gr
Posts: 54
Joined: Tue Apr 19, 2011 10:32 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by deadlock_gr »

Ah, the question says:

how many distinct instances of the interceptor class will be used to service these two calls?

NOT how many interceptor instances will be created.

So, I take back my observation.

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by ramy6_1 »

Hello ,

What will be the case if the business method is stateful session bean (instead of stateless in the question ).

I believe the answer will be TWO distinct instances of the interceptor class will be used.

Is that right ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

Yes, you are right.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

If two different clients call SLSB will container provide them same proxy or different proxy referencing this bean?
If it is same proxy which references the same instance of the bean - does it mean that the bean is accessed by two threads at the same time?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

Proxy instances are transparent to the bean developer. So whether it is one proxy or multiple, it depends on the container. In either case, it is container's responsibility to not let a bean be executed by multiple threads at the same time.

HTH,
Paul
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

So in this example there are not accessed by multiple threads at the same time?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

Your statement, "So in this example there are not accessed by multiple threads at the same time?" is too vague. So I am not sure what exactly are you getting at.
Here are the facts -
1. The container will ensure that two threads will not execute on the same bean class instance at the same time. (Ignoring singleton beans for now).

2. There can be multiple clients that might be trying to access the same bean (notice the difference between bean and bean class instance) at the same time. They can do that.

You might also want to read the explanation given with the question again. Let me know if it still isn't clear.
-Paul.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

Unfortunately, I am not getting how exactly two customers can access same bean at the same time, preserving thread-safety. When we say "same time", is it really same-time (concurrent) or it is just accessed in parallel?
On the other way, if there is no state in SLSB, why would container maintain thread-safety?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

The container may create two instances of the bean class. Or the container may sequence the calls to the same instance one after another.

Thready safety is a requirement imposed by the specification. The idea is to free the programmer from worrying about multiple threads running through the code and freeing the programmer from explicitly using synchronization mechanisms.
"same time" is really from clients perspective. Two separate clients can call upon a bean method at the same time. You can start two threads and have them execute the same method on the same instance, right? That, in common language, is "same time". Of course, there is JVM scheduling and number of CPU cores involved but that is irrelevant.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

Or the container may sequence the calls to the same instance one after another. In this case can we say that they are accessed at the the same time?

I think it would be more precise then to say that both client will just get reference(or proxy) to the same bean, but not exactly get bean accessed at the same time.
Two separate clients can call upon a bean method at the same time. You can start two threads and have them execute the same method on the same instance, right?
In our example, let's say bean B invokes bean's A aM() method, will the other bean C able to execute same Am() method, before bean B did not exit the same aM() method or his call will be blocked?
The exact question is : will container create separate threads to allow multithreaded access or container will have to serialize method calls?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

A "bean" is a logical entity. Reference to a bean doesn't mean reference to a bean class instance. Thus, same "bean" doesn't necessarily mean same bean class instance. So yes, multiple client can invoke calls on the same bean at the same time. Container may either serialize the invocations to the same instance or may create multiple instances. It is up to the container.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

Specification says:
The container serializes calls to each stateful and stateless session bean instance. Most containers will support many instances of a session bean executing concurrently; however, each instance sees only a serialized sequence of method calls. Therefore, a stateful or stateless session bean does not have to be coded as reentrant.
The container must serialize all the container-invoked callbacks (that is, the business method interceptor methods, lifecycle callback interceptor methods, timeout callback methods, beforeCompletion methods, and so on), and it must serialize these callbacks with the client-invoked business method calls.
By default, clients are allowed to make concurrent calls to a stateful session object and the container is required to serialize such concurrent requests. Note that the container never permits multi-threaded access to the actual stateful session bean instance.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by admin »

Yes. Not sure what is your point. It says the same thing.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.391 :

Post by johnlong »

I think that execute at the same time means multithreaded access.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests