Although Singletons no longer loved by many professionals for various reasons - I think there is a good use case for Ssingleton`.
However, ask yourself if the requirements of the web server really require a single, common configuration for all aspects of the server. And if so, how soon will they change soon? For example, let's say 3 websites are hosted on your server. And now you will be asked to set bandwidth limits for one of them - how do you configure this?
I really approve of a good singleton - although you should consider the whole thread safety issue when initializing in a multi-threaded environment (although it looks like you will not have this problem since you will not have multiple threads before initializing it.
Keep in mind that singlets live within ClassLoader , and if you have multiple ClassLoader (for example, for each .war download), you will have multiple copies of this " Singleton ".
Consider all aspects of your server, and if it's really simple - A Singleton save you a lot of headache - and make the code much more convenient and readable. As mentioned in one or two answers - dependency injection is a good alternative to Singleton - they help you simplify your work with JUnits.
One note about JUnit, I understand (have not tried it yet) that Mockit can allow you to replace the actual implementation during a test run, so you can create different JUnit test cases for different scenarios without changing your Singleton to test.
source share