• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session bean

 
Arathi Raj
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can any one tell me what will happen if we use class variable in stateful session bean instead of instance variable. what about stateless bean.

Thanks
ARathi
 
Anand Ko
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
life of the variable will be that of the bean (for both stateless or stateful). I guess, u need to take care of the state if u are going to use.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use class variables instead of instance variables when you want to have overall information for the bean. For example, the number of times that the beans being created or activated, etc.

But as others said, you must be very sure about the state/data of the bean, otherwise, it is very easy for the data to be corrupted.

Nick
 
Soni Prasad
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But according to specifications:
"An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final."

Then how can one use class variables(Static variables) in EJBs. Am I confused
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic