Hi: I have a multi thread Java program. There are many singletons. I am wondering whether singleton would decrease the performance of a multi thread program, especially throughput. Some Singleton is simply a single object, some singleton are concurrentHashmap and/or atomicinteger.
If your singletons are immutable then they won't cause a decrease in performance.
However as you said, if there are concurrent (synchronized) data structure singletons in your code then your performance will be decreased when compared to non-concurrent data structures.
Basically, think objects as data holders with some methods on them and now think that you have a linked list in your code and many threads are running concurrently and modifying that linked list. Analogous to this example, your singleton data structure is data holder and many threads are trying to update it and the system is staying consistent with locks.
Long story short, I don't think that having singletons in concurrent systems will make a significant difference in performance unless they hold a data structure updated by multiple threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With