Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
A session bean represents a single Java Platform 2, Enterprise Edition (J2EE) server application, which handles business tasks for its client inside the server.
When a user and computer exchange a dialog, an interactive session occurs. A session bean resembles an interactive session in that a session bean has only one client. After a client terminates, the session bean also ends, as does the relationship between the session bean and the client.
When a client accesses a server application, the client session bean begins. After the client stops, the session bean stops and is no longer related to the client. Stateful session beans and stateless session beans are the two types of session beans.
Stateful session bean instance variables, which indicate the state of the client-bean interaction, are retained for the client-bean interaction period. The state is no longer retained when interaction ends. Stateless session bean instance variables (those containing the state of the session) are retained as long as the method is invoked. The state is not retained for the entire session duration.
There are two critical circumstances where session beans should be used. One is when only one client will be accessing a bean instance during a particular period of time. The second is when the state of the bean need not remain persistent, meaning it will only last a few hours.