4 ms·
In may frameworks service layers are usually implemented as singletons to prevent the expansion of memory requirements with a lot of throughput. However, servic
by ascotan 12y ago
In may frameworks service layers are usually implemented as singletons to prevent the expansion of memory requirements with a lot of throughput. However, services designed like this _should_ be stateless. Basically they exist to do the heavy lifting of data transformation. There no real problem with this.
The problem comes when you mix state into a singleton. State-full singletons are basically global variables. Even if you design all your methods as transactional/synchronized/blah/blah you will run into issue where the state of the singleton isn't what you expected because it was changed via a different method/thread/blah/blah.
Basically this a school of hard knocks thing. They're great, until you have to debug it in production.