{"id":7140,"date":"2013-01-19T10:15:21","date_gmt":"2013-01-19T15:15:21","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=7140"},"modified":"2013-03-21T09:33:30","modified_gmt":"2013-03-21T14:33:30","slug":"thread-safe-singleton-examples","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=7140","title":{"rendered":"Thread Safe Singleton Examples"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#The_solution_of_Bill_Pugh\">The solution of Bill Pugh<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"The_solution_of_Bill_Pugh\"><h3>The solution of Bill Pugh<\/h3><\/span>\n<pre lang=\"java\">\r\npublic class Singleton {\r\n        \/\/ Private constructor prevents instantiation from other classes\r\n        private Singleton() { }\r\n \r\n        \/**\r\n        * SingletonHolder is loaded on the first execution of Singleton.getInstance() \r\n        * or the first access to SingletonHolder.INSTANCE, not before.\r\n        *\/\r\n        private static class SingletonHolder { \r\n                public static final Singleton INSTANCE = new Singleton();\r\n        }\r\n \r\n        public static Singleton getInstance() {\r\n                return SingletonHolder.INSTANCE;\r\n        }\r\n}\r\n<\/pre>\n<span id=\"References\"><h3>References<\/h3><\/span>\n<p>* <a href=\"http:\/\/en.wikipedia.org\/wiki\/Singleton_pattern\">http:\/\/en.wikipedia.org\/wiki\/Singleton_pattern<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The solution of Bill Pugh public class Singleton { \/\/ Private constructor prevents instantiation from other classes private Singleton() { } \/** * SingletonHolder is loaded on the first execution of Singleton.getInstance() * or the first access to SingletonHolder.INSTANCE, not &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=7140\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[332,330,559,328,329],"class_list":["post-7140","post","type-post","status-publish","format-standard","hentry","category-java","tag-designpattern","tag-doublecheckedlocking","tag-java","tag-singleton","tag-threadsafe"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-1Ra","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7140"}],"version-history":[{"count":4,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7140\/revisions"}],"predecessor-version":[{"id":7567,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7140\/revisions\/7567"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}