Member 11745740 wrote:
Yes, of course I know it. Servlet is multi-thread, I am wondering if a method has a static attribute matters.
Well, about your "I know it" please see my comment to the question. And as to the threading, let's see:
Simple analysis could show you that using a static method add problems with multithreading, can only remove some of them. First of all, static method is the method not using "this", having no access to the instance of its class. Please see my past answers for explanations (it does not matter that they answered .NET, and of one the C++ questions; the principles are exactly the same):
Type casting in c#[
^],
C# windows base this key word related and its uses in the application[
^],
Catch 22 - Pointers to interface objects die when function using them is made static.[
^],
What makes static methods accessible?[
^].
When two thread access different objects, the threads don't interfere with each other. If you use only static methods and only the objects passed to them as parameters, you can easily guarantee that two threads always work with different object. If some object is shared between tho threads, you can big problem is you don't synchronize the access to it. I hope you don't have to explain it. And best synchronization is no synchronization.
So, if you use an instant method (not-static) method in two different threads, it all depends on what is that "this" object. If you have two calls in different threads to the same method called on the same object, you are working with the same "this", same object, and it does not even matter that you are calling the same method: you can still access the same object if different thread call different instance methods on the same instance. Now, it depends on what you access through this "this". So, your threads clash and may need synchronization, such as locking.
—SA
—SA