<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Singleton is a bad design pattern</title>
	<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/</link>
	<description>Good judgement comes from experience, and experience comes from bad judgement.</description>
	<pubDate>Wed, 07 Jan 2009 17:41:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: SRK</title>
		<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-20714</link>
		<dc:creator>SRK</dc:creator>
		<pubDate>Sun, 05 Oct 2008 07:04:05 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-20714</guid>
		<description>Hi,
 
I have gone through the entire dicussion on the thread, I agree with JBX.

There is no way, the singleton getinstance can cause peformance bottle neck</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I have gone through the entire dicussion on the thread, I agree with JBX.</p>
<p>There is no way, the singleton getinstance can cause peformance bottle neck</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbx</title>
		<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9488</link>
		<dc:creator>jbx</dc:creator>
		<pubDate>Tue, 03 Jun 2008 13:18:41 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9488</guid>
		<description>oops, sorry wanted to say:

P.S. you copied the code 'incorrectly'</description>
		<content:encoded><![CDATA[<p>oops, sorry wanted to say:</p>
<p>P.S. you copied the code &#8216;incorrectly&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jbx</title>
		<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9487</link>
		<dc:creator>jbx</dc:creator>
		<pubDate>Tue, 03 Jun 2008 13:15:40 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9487</guid>
		<description>I dont agree with you that the Singleton pattern is a bad pattern. Like every weapon, it has to be used correctly.

In your case, the bottleneck wasnt even in the getInstance() because your previous programmer made sure that the method only synchronizes when the instance is null, i.e. only the first time MyTableAccess is requested. From that point onwards, each time getInstance() is called the myInstance is not null and the synchronized block is never executed. I guess you blamed the wrong part of the code.

In your case it is the synchronized method getRecord() that is probably causing the bottleneck not the singleton factory method. (Was the programmer afraid of some kind of concurrent access?) By creating a new instance with each getInstance() request you simply avoided the synchronisation of that method not of the singleton factory.

In these kinds of situations, it probably makes best sense to use connection pooling (like DBCP or C3P0) with your database and use the singleton pattern with the connection pool itself. This way you can easily configure your application to allow concurrent but managed connections.


P.S. you copied the code correctly and this line:
private MyTableAccess myInstance;

should have been:
private static MyTableAccess myInstance;

otherwise it wouldnt even have compiled.</description>
		<content:encoded><![CDATA[<p>I dont agree with you that the Singleton pattern is a bad pattern. Like every weapon, it has to be used correctly.</p>
<p>In your case, the bottleneck wasnt even in the getInstance() because your previous programmer made sure that the method only synchronizes when the instance is null, i.e. only the first time MyTableAccess is requested. From that point onwards, each time getInstance() is called the myInstance is not null and the synchronized block is never executed. I guess you blamed the wrong part of the code.</p>
<p>In your case it is the synchronized method getRecord() that is probably causing the bottleneck not the singleton factory method. (Was the programmer afraid of some kind of concurrent access?) By creating a new instance with each getInstance() request you simply avoided the synchronisation of that method not of the singleton factory.</p>
<p>In these kinds of situations, it probably makes best sense to use connection pooling (like DBCP or C3P0) with your database and use the singleton pattern with the connection pool itself. This way you can easily configure your application to allow concurrent but managed connections.</p>
<p>P.S. you copied the code correctly and this line:<br />
private MyTableAccess myInstance;</p>
<p>should have been:<br />
private static MyTableAccess myInstance;</p>
<p>otherwise it wouldnt even have compiled.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9442</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 02 Jun 2008 05:46:36 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9442</guid>
		<description>Our temporary solution is to change "getInstance" to create new instance everytime the method is called. Synchronized is removed from the method. This will have minimum impact to the whole application.

Long term, we are revamping the whole application to remove the pattern altogether.</description>
		<content:encoded><![CDATA[<p>Our temporary solution is to change &#8220;getInstance&#8221; to create new instance everytime the method is called. Synchronized is removed from the method. This will have minimum impact to the whole application.</p>
<p>Long term, we are revamping the whole application to remove the pattern altogether.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger</title>
		<link>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9389</link>
		<dc:creator>Roger</dc:creator>
		<pubDate>Sat, 31 May 2008 23:00:04 +0000</pubDate>
		<guid>http://twit88.com/blog/2008/05/31/singleton-is-a-bad-design-pattern/#comment-9389</guid>
		<description>Hello, we had a very similar case a few years ago but in the end the whole app was rewritten from scratch since there where pieces of code like this everywhere causing performance issues, however i am very interested to know how you solved this problem.

thanks</description>
		<content:encoded><![CDATA[<p>Hello, we had a very similar case a few years ago but in the end the whole app was rewritten from scratch since there where pieces of code like this everywhere causing performance issues, however i am very interested to know how you solved this problem.</p>
<p>thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
