<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Java Creational Design Patterns &#8211; Singleton Pattern	</title>
	<atom:link href="https://www.opencodez.com/java/singleton-pattern.htm/feed" rel="self" type="application/rss+xml" />
	<link>https://www.opencodez.com/java/singleton-pattern.htm</link>
	<description>develope &#124; share &#124; reuse</description>
	<lastBuildDate>Tue, 10 Dec 2019 14:40:54 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<!--Theme by MyThemeShop.com-->
	<item>
		<title>
		By: Peter		</title>
		<link>https://www.opencodez.com/java/singleton-pattern.htm/comment-page-1#comment-92672</link>

		<dc:creator><![CDATA[Peter]]></dc:creator>
		<pubDate>Fri, 02 Aug 2019 14:12:11 +0000</pubDate>
		<guid isPermaLink="false">https://www.opencodez.com/?p=4391#comment-92672</guid>

					<description><![CDATA[the OCP course material implies it is better to use an inner class to do the singleton initialization.
This way, you don&#039;t need a synchronized block, and it only gets initialized when used.
The example they use looks like this:

public class Logger {
 private Logger() {
  // private constructor
 }

 public static class LoggerHolder {
  public static Logger logger = new Logger();
 }

 public static Logger getInstance() {
  return LoggerHolder.logger;
 }

 public void log(String s) {
  // log implementation
  System.err.println(s);
 }
}]]></description>
			<content:encoded><![CDATA[<p>the OCP course material implies it is better to use an inner class to do the singleton initialization.<br />
This way, you don&#8217;t need a synchronized block, and it only gets initialized when used.<br />
The example they use looks like this:</p>
<p>public class Logger {<br />
 private Logger() {<br />
  // private constructor<br />
 }</p>
<p> public static class LoggerHolder {<br />
  public static Logger logger = new Logger();<br />
 }</p>
<p> public static Logger getInstance() {<br />
  return LoggerHolder.logger;<br />
 }</p>
<p> public void log(String s) {<br />
  // log implementation<br />
  System.err.println(s);<br />
 }<br />
}</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 20/23 objects using disk
Page Caching using disk: enhanced 
Database Caching 1/12 queries in 0.004 seconds using disk

Served from: www.opencodez.com @ 2026-04-10 17:20:39 by W3 Total Cache
-->