Java singleton - elaborate
Posted on 2014-11-30
I wonder when it is a bad idea to use singletons in Java.
Specifically I am to build an API where files will be submitted to my API (or actually the file name and then the file will be located in a specific directory).
There are no specifications on how many transactions needs to be handled. If there would have been my stomach tells me it would be good to have a singleton taking care adding to of the inqueue and making sure it is not bigger then MAX_ALLOWED_SIZE (a value set to a reasonable figure to make sure the system is stable).
Something I do know is that I need to have a very good idea on how to make the code testable. Something that is abit tricky when it comes to singletons.
-On the system level - performance wise maybe
Please elaborate on when to use a singleton and when not, and also how to handle Junit testing and also if possible a good way to handle performance testing.