On the problem of controller singleton of springmvc under multithreaded request

Entities loaded in

1.springmvc mode are singleton mode. In that singleton, the variables are shared, and the test shared variables are shared under multiple thread requests. But the function methods in the class are not blocked? Why don"t all the immortals explain why?

Feb.28,2021

singleton is not directly related to blocking; blocking is a means of security control to access resources when concurrency; routine can be achieved by means of Synchronize keywords, lock, thread local variables, etc.
singleton is a design pattern, which is to reduce the consumption of system resources caused by instance creation.


A singleton will not block normally unless you add a synchronized or other lock to the method.


to quote my previous answer-
I personally think that you have confused singletons with thread safety. Singletons do not mean thread safety, and multiple threads accessing singletons at the same time also have concurrency problems unless you manually add locks. Through an example, how much do you think the count will be in the end?

  

Singleton is not single-threaded

Menu