Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Bean Doubt

 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Which statements about stateful and stateless session beans are true?
(Choose all that apply.)

a). Only stateful session beans support transactions.
b). Only stateful session beans can be passivated.
c). Only stateful session beans have a 'setSessionContext' method.
d). Both stateful and stateless session beans can support
overloaded 'ejbCreate' methods.
e). Both stateful and stateless session beans can implement
the 'javax.ejb.SessionSynchronization' interface.
f). Both stateful and stateless session beans can have instance variable state.

ans given : b,f - how a stateless session bean can have state in an instance variable.
my answer : b
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthikeyan,
answers B and F are correct. session conversational state is different from instance variables state. but in stateless session bean, if you declare any instance variables, becareful in handling them. or you will see unwanted results.

thanks,
Ugender
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see this thread
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear about option b.
stateless session beans can also be passivated but their passivation is not required and in their normal lifecycle their passivation is not required.
**and one more,in all types of beans we have to define ejbPassivate()
 
Patrick Williams
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj, I'm not sure I agree with you. Although those beans inherit those methods from javax.ejb.SessionBean, they are never called in a stateless session bean. Stateless beans are "awake" as they sit in the instance pool so there is no need to wake them up (ejbActivate())or put them to sleep (ejbPassivate()). Also, they do not keep conversational state so there is no need to use these methods no reload the instance with the related client. If you have HF EJB, pg 223 has the lifecycle diagram for both stateful and stateless session beans.

HTH
 
Balaji Anand
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that the answers are b and f.
Raj, the stateless session bean never get a call to passivate and activate. they are there in the SessionBean just because there is only one common interface be it stateful or stateless.
Stateless session bean never gets passivated
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic