Use a session bean if:
- Only one client has access to bean at any given time
- State of bean is not persistent
- Bean represent a web service
Use a Stateful Session bean if:
- Bean state represent client interaction
- Bean needs to hold client data across interactions
- Bean acts as a client mediator to other beans
- Need thread-safe interactions
Session Bean cardinality(taken from DevelopIntelligence)
From the diagram, you can see that Stateless and Singleton beans looks very similar when it comes to Client-bean instances, except that in singleton all the clients access single object while in Stateless some objects are uses by clients and returned back to pool.
Developing a Session Bean
Steps to create a session bean:
- Define business logic interface
- Annotate the business interface
- Create the session bean, implementing the interface
- Annotate class defining type
- Compile, deploy and debug as discussed above
Advertisements
One thought on “Choosing and developing a Session Bean”