Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking at code how to differentiate between Stateless and Stateful

 
Harsh Mahey
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Can any one tell me how do i differentiate looking at the code if the code is for stateless or stateful bean in j2ee/ejb environment.
I know the entry in xml file helps in doing this but other then this is there any difference in the code.
Thanks
Harsh
 
rahul dighe
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new to ejb ,
but I think without knowing the intent of the code , it would be almost impossible to say whether this particular bean can be stateful or stateless, i mean the only difference as i see is that if you can re initialize the bean to its earlier state it essentially would end up being a stateful bean ? wouldn't it ?(ignoring the fact of course that activation/passivation wont' occur) and you manage to do it in your code without the containers help to achieve statefulness ?
 
Geeta Ramasami
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually in stateful session bean u'll pass a paramter to the create method of the bean which would be used in maintaining the state of the bean.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't tell from the code (unless the bean implements the SessionSynchronization interface, in which case you know it's stateful, but that's a rare case). The only way to know is by looking at the deployment descriptor.
Kyle
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can see it in your ejb-jsr.xml file ->
<session-type> tag showas if it's Stateful or
Stateless..
 
Parsuram panigrahi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is difference in the ejbCreate method signature. The ejbCreate method of stateless session bean is empty where as that of stateful session bean is not. The other difference is in the deployment descriptor.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Parsuram panigrahi:
There is difference in the ejbCreate method signature. The ejbCreate method of stateless session bean is empty where as that of stateful session bean is not. The other difference is in the deployment descriptor.

Actually, it is possible to have a stateful session bean with an empty ejbCreate() signature, too, which is why I didn't bring it up. But you're right that if you find an ejbCreate() and ejbPostCreate() signature that's not empty then it's a sure sign it's a stateful bean.
Kyle
[ March 18, 2003: Message edited by: Kyle Brown ]
 
Vikram Prabhu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, the concerete way to find out if a bean is stateful or stateless is only deployment descriptor. As Kyle said, stateful bean's create method not necessarily has a parameter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic