<p>I am merging a CVS branch and one of the larger changes is the replacement wherever it occurs of a Singleton pattern with abstract classes that have a static initialisation block and all static methods.</p>

<p>Is this something that's worth keeping since it will require merging a lot of conflicts, what sort of situation would I be looking at for this refactoring to be worthwhile?</p>

<p>We are running this app under Weblogic 8.1 (so JDK 1.4.2)</p>

<hr>

<p>sorry Thomas, let me clarify..</p>

<p>the HEAD version has the traditional singleton pattern (private constructor, getInstance() etc)</p>

<p>the branch version has no constructor, is a 'public abstract class' and modified all the methods on the object to be 'static'. The code that used to exist in the private constructor is moved into a static block.</p>

<p>Then all usages of the class are changed which causes multiple conflicts in the merge.</p>

<p>There are a few cases where this change was made.</p>

[{'answer_id': 28251, 'author': 'EdgarVerona', 'author_id': 3068, 'author_profile': 'https://Stackoverflow.com/users/3068', 'pm_score': 0, 'selected': False, 'text': '<p>Does this discussion help?  (I don\'t know if it\'s taboo to link to another programming forum, but I\'d rather not just quote the whole discussion =) )</p>\n\n<p><a href="http://forums.sun.com/thread.jspa?threadID=5221231&amp;messageID=9898827" rel="nofollow noreferrer">Sun Discussion on this subject</a></p>\n\n<p>The verdict seems to be that it doesn\'t make enough of a difference to matter in most cases, though technically the static methods are more efficient.</p>\n'}, {'answer_id': 28255, 'author': 'Damien B', 'author_id': 3069, 'author_profile': 'https://Stackoverflow.com/users/3069', 'pm_score': 5, 'selected': True, 'text': '<p>From a strict runtime performance point of view, the difference is really negligible. The main difference between the two lies down in the fact that the "static" lifecycle is linked to the classloader, whereas for the singleton it\'s a regular instance lifecycle. Usually it\'s better to stay away from the ClassLoader business, you avoid some tricky problems, especially when you try to reload the web application.</p>\n'}, {'answer_id': 28260, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 2, 'selected': False, 'text': "<p>If my original post was the correct understanding and the discussion from Sun that was linked to is accurate (which I think it might be), then I think you have to make a trade off between clarity and performance.</p>\n\n<p>Ask yourself these questions:</p>\n\n<ol>\n<li>Does the Singleton object make what I'm doing more clear?</li>\n<li>Do I need an object to do this task or is it more suited to static methods?</li>\n<li>Do I need the performance that I can gain by not using a Singleton?</li>\n</ol>\n"}, {'answer_id': 28271, 'author': 'levand', 'author_id': 3044, 'author_profile': 'https://Stackoverflow.com/users/3044', 'pm_score': 4, 'selected': False, 'text': "<p>I would use a singleton if it needed to store any state, and static classes otherwise. There's no point in instantiating something, even a single instance, unless it needs to store something.</p>\n"}, {'answer_id': 28312, 'author': 'Cem Catikkas', 'author_id': 3087, 'author_profile': 'https://Stackoverflow.com/users/3087', 'pm_score': 2, 'selected': False, 'text': "<p>From my experience, the only thing that matters is which one is easier to mock in unit tests. I always felt Singleton is easier and natural to mock out. If your organization lets you use JMockit, it doesn't matter since you can overcome these concerns.</p>\n"}, {'answer_id': 28721, 'author': 'Mark Renouf', 'author_id': 758, 'author_profile': 'https://Stackoverflow.com/users/758', 'pm_score': 4, 'selected': False, 'text': "<p>Static is bad for extensibility since static methods and fields cannot be extended or overridden by subclasses. </p>\n\n<p>It's also bad for unit tests. Within a unit test you cannot keep the side effects of different tests from spilling over since you cannot control the classloader. Static fields initialized in one unit test will be visible in another, or worse, running tests concurrently will yield unpredictable results.</p>\n\n<p>Singleton is generally an ok pattern when used sparingly. I prefer to use a DI framework and let that manage my instances for me (possibly within different scopes, as in Guice).</p>\n"}, {'answer_id': 51087, 'author': 'Rob Spieldenner', 'author_id': 5118, 'author_profile': 'https://Stackoverflow.com/users/5118', 'pm_score': 0, 'selected': False, 'text': "<p>Write some code to measure the performance.  The answer is going to be dependent on the JVM(Sun's JDK might perform differently than JRockit) and the VM flags your application uses.</p>\n"}]
['https://Stackoverflow.com/questions/28241', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']