Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Murach's Java Servlets and JSP this week in the Servlets 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: 8903

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: 8903

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: 8903

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: 8903

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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instance variable in session EJB
 
Similar Threads
Stateless Session Bean
New to EJB.. Session Bean
Confused with Stateless Session Bean
What is the Difference between statefull and stateless session bean?
Session Bean Doubt