aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Looking at code how to differentiate between Stateless and Stateful Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Looking at code how to differentiate between Stateless and Stateful" Watch "Looking at code how to differentiate between Stateless and Stateful" New topic
Author

Looking at code how to differentiate between Stateless and Stateful

Harsh Mahey
Greenhorn

Joined: Nov 07, 2002
Posts: 5
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

Joined: Apr 17, 2001
Posts: 44
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 ?


<BR>Rahul Dighe
Geeta Ramasami
Ranch Hand

Joined: Mar 05, 2003
Posts: 72
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
you can see it in your ejb-jsr.xml file ->
<session-type> tag showas if it's Stateful or
Stateless..


Asher Tarnopolski
SCJP,SCWCD
Parsuram panigrahi
Greenhorn

Joined: Feb 18, 2003
Posts: 17
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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

Joined: Nov 18, 2002
Posts: 3
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.


Learning Java...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking at code how to differentiate between Stateless and Stateful