Session is not thread-safe

Source: Internet
Author: User

Session is not thread-safe

When using hibernate to develop DAO module, we have the most dealings with the session, so how to manage the session reasonably and avoid the frequent creation and destruction of the session is very important for improving the performance of the system. It used to be done automatically through the Eclipse plug-in to automate the code, but the effect was good, but always uncomfortable (not reading the lengthy code), so now you're going to implement the session Management code yourself. We know that the session is created by Sessionfactory, and the implementation of Sessionfactory is thread-safe, and multiple concurrent threads can access a sessionfactory and get a session instance from it. So is the session thread-safe? Unfortunately, the answer is no. The session contains state information related to database operations, so if multiple threads are using a session instance for CRUD at the same time, it is likely to cause confusion in data access, can you imagine that you simply cannot predict the execution sequence of the thread of your record to operate the situation?

Session is not thread-safe

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.