{"id":38482,"date":"2023-12-11T14:44:35","date_gmt":"2023-12-11T06:44:35","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=38482"},"modified":"2023-12-11T14:44:35","modified_gmt":"2023-12-11T06:44:35","slug":"%e8%af%b7%e4%bd%a0%e6%89%8b%e5%86%99%e4%b8%80%e4%b8%8b%e5%8d%95%e4%be%8b%e6%a8%a1%e5%bc%8f%e4%bb%a3%e7%a0%81%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e8%af%b7%e4%bd%a0%e6%89%8b%e5%86%99%e4%b8%80%e4%b8%8b%e5%8d%95%e4%be%8b%e6%a8%a1%e5%bc%8f%e4%bb%a3%e7%a0%81%ef%bc%9f\/","title":{"rendered":"\u8bf7\u4f60\u624b\u5199\u4e00\u4e0b\u5355\u4f8b\u6a21\u5f0f\u4ee3\u7801\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u53c2\u8003\u56de\u7b54\uff1a<\/p>\n<p>\u61d2\u6c49\u5f0f\u5355\u4f8b\u6a21\u5f0f\uff1a\u5ef6\u8fdf\u5b9e\u4f8b\u5316\uff0c\u4f46\u8282\u7701\u7a7a\u95f4<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-java&quot;&quot; lang=&quot;&quot;java&quot;&quot;&gt;package com.sxh.singleton;<\/p>\n<p>    public class SingleTon {<\/p>\n<p>    \/*<br \/>\n    * volatile\u5173\u952e\u5b57\u786e\u4fdd\uff1a\u5f53uniqueInstance\u53d8\u91cf\u88ab\u521d\u59cb\u5316\u4e3aSingleTon\u5b9e\u4f8b\u65f6\uff0c\u591a\u4e2a\u7ebf\u7a0b\u80fd\u6b63\u786e\u7684\u5904\u7406uniqueInstance\u53d8\u91cf<br \/>\n    * \u5206\u6790\uff1avolatile\u4fee\u9970\u7684\u6210\u5458\u53d8\u91cf\uff0c\u5728\u6bcf\u6b21\u88ab\u7ebf\u7a0b\u8bbf\u95ee\u65f6\uff0c\u90fd\u5f3a\u5236\u6027\u7684\u4ece\u5171\u4eab\u5185\u5b58\u91cd\u8bfb\u8be5\u6210\u5458\u7684\u503c\uff1b<br \/>\n    * \u5f53\u503c\u53d1\u751f\u53d8\u5316\u662f\uff0c\u5f3a\u5236\u7ebf\u7a0b\u5c06\u53d8\u5316\u503c\u5199\u5165\u5171\u4eab\u5185\u5b58\uff0c\u4efb\u4f55\u65f6\u5019\u4e0d\u540c\u7ebf\u7a0b\u603b\u662f\u770b\u5230\u4f60\u67d0\u4e2a\u6210\u5458\u53d8\u91cf\u7684\u540c\u4e00\u4e2a\u503c<br \/>\n    * *\/<br \/>\n    private volatile static SingleTon uniqueInstance;\/\/\u5229\u7528\u4e00\u4e2a\u9759\u6001\u53d8\u91cf\u6765\u8bb0\u5f55SingleTon\u7c7b\u7684\u552f\u4e00\u5b9e\u4f8b<br \/>\n    \/\/\u5176\u4ed6\u6709\u7528\u7684\u5355\u4ef6\u7c7b\u7684\u6570\u636e<br \/>\n    private SingleTon(){} \/\/\u7c7b\u5916\u65e0\u6cd5\u8bbf\u95ee<br \/>\n    public  static SingleTon getInstance(){<\/p>\n<p>    \/*<br \/>\n    * \u4f7f\u7528\u201d\u53cc\u91cd\u68c0\u67e5\u52a0\u9501\u201c,\u5728getInstance\u4e2d\u51cf\u5c11\u4f7f\u7528\u540c\u6b65<br \/>\n    * \u9996\u5148\u68c0\u67e5\u662f\u5426\u5b9e\u4f8b\u5df2\u7ecf\u521b\u5efa\u4e86\uff0c\u5982\u679c\u5c1a\u672a\u521b\u5efa\uff0c\u624d\u8fdb\u884c\u540c\u6b65\uff1b\u53ea\u6709\u7b2c\u4e00\u6b21\u8bbf\u95eegetInstance\u4f1a\u540c\u6b65<br \/>\n    *\/<\/p>\n<p>    if(uniqueInstance==null){  \/\/\u786e\u4fdd\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b<br \/>\n        synchronized (SingleTon.class) { \/\/\u591a\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0d\u4f1a\u51fa\u73b0\u95ee\u9898\uff0c\u7ebf\u7a0b\u540c\u6b65\u95ee\u9898<br \/>\n            if(uniqueInstance==null){<br \/>\n             uniqueInstance=new SingleTon();\/\/\u5982\u679c\u6211\u4eec\u4e0d\u9700\u8981\u8fd9\u4e2a\u5b9e\u4f8b\uff0c\u5219\u6c38\u8fdc\u4e0d\u4f1a\u4ea7\u751f<br \/>\n            }<br \/>\n        }<br \/>\n     }<br \/>\n     return uniqueInstance;<br \/>\n    }<br \/>\n    \/\/\u5176\u4ed6\u6709\u7528\u7684\u5355\u4ef6\u7c7b\u7684\u65b9\u6cd5\uff0c\u5355\u4ef6\u7c7b\u4e5f\u53ef\u4ee5\u662f\u4e00\u822c\u7684\u7c7b\uff0c\u5177\u6709\u4e00\u822c\u7684\u6570\u636e\u548c\u65b9\u6cd5<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u997f\u6c49\u5f0f\u5355\u4f8b\u6a21\u5f0f\uff1a\u6025\u5207\u7684\u521b\u5efa\u5b9e\u4f8b\uff0c\u800c\u4e0d\u7528\u5ef6\u8fdf\u5b9e\u4f8b\u5316<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-java&quot;&quot; lang=&quot;&quot;java&quot;&quot;&gt;package com.sxh.singleton;<\/p>\n<p>public class SingleTon {<\/p>\n<p>    private volatile static SingleTon uniqueInstance=new SingleTon();<br \/>\n    \/\/\u5176\u4ed6\u6709\u7528\u7684\u5355\u4ef6\u7c7b\u7684\u6570\u636e<br \/>\n    private SingleTon(){} \/\/\u7c7b\u5916\u65e0\u6cd5\u8bbf\u95ee<br \/>\n    public  static SingleTon getInstance(){<br \/>\n         return uniqueInstance;<br \/>\n    }<\/p>\n<p>    \/\/\u5176\u4ed6\u6709\u7528\u7684\u5355\u4ef6\u7c7b\u7684\u65b9\u6cd5\uff0c\u5355\u4ef6\u7c7b\u4e5f\u53ef\u4ee5\u662f\u4e00\u822c\u7684\u7c7b\uff0c\u5177\u6709\u4e00\u822c\u7684\u6570\u636e\u548c\u65b9\u6cd5<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>IoDH\u5b9e\u73b0\u5355\u4f8b\u6a21\u5f0f<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-java&quot;&quot; lang=&quot;&quot;java&quot;&quot;&gt;package com.sxh.singleton;<\/p>\n<p>public class SingleTon {<\/p>\n<p>    private SingleTon(){} \/\/\u7c7b\u5916\u65e0\u6cd5\u8bbf\u95ee<br \/>\n    private static class HolderClass{ \/\/\u9759\u6001\u5185\u90e8\u7c7b<br \/>\n        private static final SingleTon uniqueinstance=new SingleTon();<br \/>\n    }<\/p>\n<p>    public  static SingleTon getInstance(){<br \/>\n        return HolderClass.uniqueinstance;<br \/>\n    }<br \/>\n    \/\/\u5176\u4ed6\u6709\u7528\u7684\u5355\u4ef6\u7c7b\u7684\u65b9\u6cd5\uff0c\u5355\u4ef6\u7c7b\u4e5f\u53ef\u4ee5\u662f\u4e00\u822c\u7684\u7c7b\uff0c\u5177\u6709\u4e00\u822c\u7684\u6570\u636e\u548c\u65b9\u6cd5<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u53c2\u8003\u56de\u7b54\uff1a \u61d2\u6c49\u5f0f\u5355\u4f8b\u6a21\u5f0f\uff1a\u5ef6\u8fdf\u5b9e\u4f8b\u5316\uff0c\u4f46\u8282\u7701\u7a7a\u95f4 &lt;pre&gt;&#038;l [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-38482","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=38482"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38482\/revisions"}],"predecessor-version":[{"id":38483,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38482\/revisions\/38483"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=38482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=38482"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=38482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}