Singleton and multi-threading are two completely unrelated fields. Singleton solves the problem of controlling objects, while multi-threading solves the problem of making full use of the capabilities of multi-core processors. It does not mean that singletons must be synchronized. Synchronization is only required when data sharing occurs. So even if you do not use singletons, but multiple objects share a resource, they still need to be synchronized; the same Reasonable, even if you use a singleton, if you don't share resources, you still don't need synchronization.
A practical example: Now there is a singleton, but the singleton method does not use any static objects, that is, there is no resource sharing, so synchronization is not required.
Personal understanding: If a singleton considers multi-threading, it must be locked, and the performance will definitely be affected. Depending on the business situation, consider using threadLocal
Singleton and multi-threading are two completely unrelated fields. Singleton solves the problem of controlling objects, while multi-threading solves the problem of making full use of the capabilities of multi-core processors.
It does not mean that singletons must be synchronized. Synchronization is only required when data sharing occurs. So even if you do not use singletons, but multiple objects share a resource, they still need to be synchronized; the same Reasonable, even if you use a singleton, if you don't share resources, you still don't need synchronization.
A practical example:
Now there is a singleton, but the singleton method does not use any static objects, that is, there is no resource sharing, so synchronization is not required.
Personal understanding: If a singleton considers multi-threading, it must be locked, and the performance will definitely be affected. Depending on the business situation, consider using threadLocal
Single cases are read-only. . There is no impact. .