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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32ca8-2b694.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32ca8-2b694.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?