In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the life cycle of ASP.NET thread safety and static variables". The content of the explanation is simple and clear, and it is easy to learn and understand. let's study and learn "what is the life cycle of ASP.NET thread safety and static variables"!
Void Application_Start start
Void Application_End ended it. It was right.
Today, I'm going to do a global application. I want to make sure that I can find it on the Internet. Oh, my God, I have everything to say.
There are about three kinds.
1.Application_Start--Application_End
2.Session_Start--Session_End
3. End of class life cycle
I did a test with four machines and found that the static variable value was constant all the time and was not destroyed because other users logged in. It was confirmed that it should be Application-level.
When a static class is accessed, a static constructor is called to create a class type object. The life cycle of the type object is the life cycle of the entire application domain, that is, the accessed static class is unloaded only when its application domain is unloaded.
Class members are divided into two categories, static members (static member) and instance members (instance member). Static members belong to the class, and instance members belong to the object, that is, instances of the class.
Briefly discuss whether there are thread safety issues with static fields (static field) and static methods (static method) in a class.
We know that calls to static fields (static field) and static methods (static method) are called through classes. Static methods are not specific instance operations and can only access static members. Instance methods can operate on specific instances, accessing both static and instance members.
So, is there an ASP.NET thread safety problem with using static methods in multithreading? It depends on whether static methods cause ASP.NET thread safety problems, depending on whether static members are used in static methods.
Because, when using the same static method in multithreading, each thread uses a copy of its own instance field (instance field) and shares a static field (static field). Therefore, if the static method does not manipulate a static member and only uses the instance field (instance field) inside the method, it will not cause security problems. However, if the static method manipulates a static field, it needs to be securely handled by mutually exclusive access in the static method.
To take a simple example, we use Console.WriteLine (); where WriteLine () is a static method of the Console.WriteLine class.
For ASP.NET thread safety, multiple clients access the server, this is an example of multithreading. As long as we understand the reason, we can safely use static method (static method) to access the database in the data access layer of the three-tier architecture.
If static methods do not use static variables, there is no thread safety problem.
Why? Because of the variables declared in the static method, each thread invokes a new one instead of sharing a storage unit. Each thread creates its own copy, so there are no thread safety issues.
Note that static variables, because they occupy a storage area when the class is loaded, are shared by every thread, so if static variables are used in static methods, there will be thread safety issues!
Thank you for reading, the above is the content of "ASP.NET thread safety and the life cycle of static variables". After the study of this article, I believe you have a deeper understanding of what the life cycle of ASP.NET thread safety and static variables is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.