The members of a class are divided into two classes, static members (static member), and instance members (instance member). A static member belongs to a class, and an instance member belongs to an object, that is, an instance of a class.
Briefly discuss whether using static fields and static methods (static method) in a class can be a thread security issue.
We know that the call of the static field and static method is called by the class. Static methods do not operate on specific instances, only static members can be accessed. An instance method can operate on a particular instance to access both static members and instance members.
So is the use of static methods in multiple threads a thread security issue? This depends on whether the static method is causing the thread-safety problem to see if the static member is used in the static method.
Because, when using the same static method in multiple threads, each thread uses a copy of its own instance field (instance field) and shares a static field (static field). So, if the static method does not manipulate a static member, using the instance field only within the method (instance field) does not cause a security issue. However, if the static method operates on a static field, it requires a secure handling in a static method using mutually exclusive access.
For a simple example, we use the Console.WriteLine (); WriteLine () is a static method of the Console.WriteLine class.
For ASP.net, multiple clients access to the server side, this is a multithreaded example. As long as we understand why, we can safely use static method to access the database in the data access layer in the three-tier architecture.