This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes instance variable in session EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "instance variable in session EJB" Watch "instance variable in session EJB" New topic
Author

instance variable in session EJB

Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi all
As I understood, a stateful session bean can maintain the client's state in its instance variable. And stateless session bean do not hold any state between invocation. Is there any particular situation where we have to declare an instance variable in a stateless session bean?
Thanks
-Sainudheen
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Is there any particular situation where we have to declare an instance variable in a stateless session bean?

You can create a resource in ejbCreate and release it in ejbRemove(). The resource is maintianed in an instance variable.


Groovy
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Easy question for me!
You can declare read-only variables.
You can also declare variables, not dependent on any particular client. For example: any connection sources that can be shared between multiple clients using the same stateless session bean.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

You can declare read-only variables.

I dont agree with this. I can always update the variable.
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
Ok Pradeep,
I will change my phrase.
You can use read-only variables in the stateless session beans that do not get updated in the code and also variables that do get updated in the code. As long as they are not dependent on any particular client, it is fine.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

When someone uses instance variables in SLSB they are meant to be client independent.
They are not read only as read only means that it cannot be updated.
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Is this correct?
A stateless session bean may only have instance variables that are specific to a bean instance but not specific to any client.

-Sainudheen
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Sainudheen Mydeen:
Is this correct?
A stateless session bean may only have instance variables that are specific to a bean instance but not specific to any client.

-Sainudheen


Yes, instance varaibles in SLSB should be used that way .
 
wood burning stoves
 
subject: instance variable in session EJB