Threadlocal in hibernate

Source: Internet
Author: User
I learned about hibernate today and saw the data connection section. I saw a threadlocal class and read these two articles online. Article.
Http://qszhuang.blogchina.com/blog/article_20407.72483.html
Http://www-900.ibm.com/developerWorks/cn/java/j-threads/index3.shtml#h5450
Threadlocal is used to implement a local variable of the thread. A local variable of the thread means that every instance of the thread will own an instance of this variable. all instances of the thread will not share this variable, or this variable is independent for each instance of the thread. In this way, there is no synchronization problem for such a variable, but it cannot be shared with the thread and cannot be used for communication between threads.
In hibernate, net. SF. hibernate. session is such a variable. servlet creates a thread for each client. That is to say, each client has a net. SF. hibernate. session instance. Net. SF. hibernate. Session corresponds to a session connected to the database. A session corresponds to a connection to the database (you cannot determine it. Check the hibernate source code tomorrow). That is to say, every client in hibernate has a connection to the database.

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.