The difference between stateful and stateless session beans

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.