Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instance variable in session EJB

 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can declare read-only variables.

I dont agree with this. I can always update the variable.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic