Thread variables in the thread pool

Source: Internet
Author: User
Thread variables in the thread pool

Do the background development, should all know thread variable this thing, can guarantee each thread to get the data and other threads, as long as do simple set/get operation, can.
-This is the premise-
Today do development, need to pass data to the outer layer in the inner function, a copy is, layer return, this method can be implemented, but I call the three layer method, means that at least change around, more changes mean more bugs, and then think of a magic thread variable can be used.

Code a change, on-line, waiting for the effect, found that the data set in the thread variable number of many times, expect only a few occurrences, and then check and check again, found that the code is not a problem, the operation is normal.

After one hours, it occurred to me that the reason for the thread pool was not really creating a new thread, that is, the contents of the thread variable that were stored in the threads.

With the idea, first search, then test, sure enough, thread pool due to not create a new thread, causing the threading variable is also the previous content, with the conclusion that the modification is very simple, one directly into the thread when set to NULL, the other is to empty after use, the two copy effect is the same. The only difference is whether the following code continues to use this value.

Related Article

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.