-
1. Re: Private attribute in a Stateless Session Bean
adrian.brock Feb 7, 2004 9:31 AM (in response to cari34)The session objects are pooled (and lazily constructed).
This means your ejbCreate() won't be invoked until the first request.
It is not when they do home.create(), this just creates a proxy to the bean without
doing anything with bean instances.
Once your object is in the pool, it won't invoke ejbCreate() again.
If you want to configure expensive resources you should consider
JCA. Or if there is no need for transactions and security and MBean.
Regards,
Adrian -
2. Re: Private attribute in a Stateless Session Bean
marc.fleury Feb 7, 2004 11:59 AM (in response to cari34)having a field in stateless only makes sense if all the sessions need that field. If the field is session specific then you need stateful sessions.
-
3. Re: Private attribute in a Stateless Session Bean
cari34 Feb 7, 2004 12:43 PM (in response to cari34)Hi Adrian and Marc,
Thank you.
The field I want to put in the stateless session bean is not session specific.
(the bean has only one method).
It holds reference to an array of objects that I want to be instatiated before the client invokes the EJB method.
So I want to instantiate these objects when the container call the ejbCreate() method.
But I want to know what happens when the same bean instance serves a different client??
Will the objects that have been instantiated when the container called ejbCreate() method be available to that new client???
And in general, is there any impact on performance to declare a private field in a Stateless session bean???
Thank you very much
Cari -
4. Re: Private attribute in a Stateless Session Bean
juha Feb 7, 2004 9:02 PM (in response to cari34)Yes the objects will be available to all clients (they're pooled). So if you use instance fields they must be immutable throughout the life cycle of the bean (or you need to figure out how to notify the bean instances of the state change)
-
5. Re: Private attribute in a Stateless Session Bean
cari34 Feb 8, 2004 5:08 AM (in response to cari34)Hi Juha,
Thank you very much.
I wandered whether there is a harm to call a singleton class from the ejbCreate method in order to retrieve the array of objects and populate
the bean's instance field with it?
I know that EJB must avoid using static fields and the singleton class has static field.
Do you think it's a good choice to do like that??
Could this raise performence issues??
I precise that the bean's method delegates every client call to the objects method contained in bean's intance field.
Thank you very much.
Cari. -
6. Re: Private attribute in a Stateless Session Bean
juha Feb 9, 2004 1:58 AM (in response to cari34)If the singleton returns immutable values it should be ok. Mutable values don't work in a cluster setup.
-
7. Re: Private attribute in a Stateless Session Bean
cari34 Feb 9, 2004 2:32 PM (in response to cari34)Thanks Juha,
Your advice is very helpfull.
Cari