In reality, many friends have misunderstood the two session beans, that there is a state is the instance has always existed, save the state after each call, and the next call to play a role, and that the stateless is an instantiation of each invocation, do not retain user information. After careful analysis and practice testing, you will find that the opposite is true:
The essential difference between stateful and stateless session beans is their lifetime.
First, explain a concept to be used-User: The user of the session bean is actually an instance of the class that invokes the EJB directly, or even a method of the instance. Different instances of the same class are different users for the session bean.
Stateful session Bean: Each user has a unique instance of itself, and during the lifetime of the user, the bean retains the user's information, which is "stateful", and the Bean's lifetime ends when the user dies (the call ends or the instance ends). That is, each user will initially get an initial bean.
Stateless session Bean:bean is added to the session pool once instantiated, and can be shared by each user. Even if the user is dead, the lifetime of the bean is not necessarily over, it may still exist in the session pool for other users to invoke. Because there is no specific user, it is not possible to maintain a user's state, so it is called a stateless bean. However, a stateless session bean is not stateless, and if it has its own attributes (variables), then the variables are affected by all the users who invoke it, which must be noted in practical applications.