{"id":76579,"date":"2026-02-22T21:09:24","date_gmt":"2026-02-22T13:09:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76579.html"},"modified":"2026-02-22T21:09:24","modified_gmt":"2026-02-22T13:09:24","slug":"%e9%9d%a2%e8%af%95%e5%bf%85%e4%bc%9a%ef%bc%9a%e6%89%8b%e5%86%99%e5%8d%95%e4%be%8b%e6%a8%a1%e5%bc%8f%ef%bc%88%e4%bb%8e%e9%9b%b6%e5%88%b0%e5%ae%8c%e7%be%8e%e7%9a%84%e4%ba%94%e7%a7%8d%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76579.html","title":{"rendered":"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09"},"content":{"rendered":"<h2>\u9762\u8bd5\u5fc5\u4f1a&#xff1a;\u624b\u5199\u5355\u4f8b\u6a21\u5f0f&#xff08;\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0&#xff09;<\/h2>\n<p>\u5728\u8bbe\u8ba1\u6a21\u5f0f\u4e2d&#xff0c;\u5355\u4f8b\u6a21\u5f0f&#xff08;Singleton Pattern&#xff09; \u662f\u6700\u7b80\u5355\u4e5f\u662f\u6700\u5e38\u8003\u7684\u4e00\u79cd\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u786e\u4fdd\u4e00\u4e2a\u7c7b\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5168\u5c40\u8bbf\u95ee\u70b9\u3002<\/p>\n<p>\u5728 Java \u540e\u7aef\u5f00\u53d1\u7684\u9762\u8bd5\u4e2d&#xff0c;\u9762\u8bd5\u5b98\u5e38\u5e38\u4f1a\u8981\u6c42\u4f60\u201c\u624b\u5199\u4e00\u4e2a\u5355\u4f8b\u201d&#xff0c;\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u8ffd\u95ee\u7ebf\u7a0b\u5b89\u5168\u3001\u6307\u4ee4\u91cd\u6392\u7b49\u95ee\u9898\u3002\u672c\u6587\u5e26\u4f60\u9010\u4e00\u51fb\u7834\u3002<\/p>\n<h3>1. \u997f\u6c49\u5f0f&#xff08;\u7ebf\u7a0b\u5b89\u5168&#xff0c;\u7b80\u5355\u76f4\u63a5&#xff09;<\/h3>\n<p>\u201c\u997f\u6c49\u201d\u7684\u610f\u601d\u662f&#xff1a;\u7c7b\u52a0\u8f7d\u65f6\u5c31\u5b8c\u6210\u4e86\u521d\u59cb\u5316&#xff0c;\u4e0d\u7ba1\u4f60\u7528\u4e0d\u7528&#xff0c;\u5148\u521b\u5efa\u51fa\u6765\u518d\u8bf4\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ 1. \u79c1\u6709\u5316\u6784\u9020\u65b9\u6cd5&#xff0c;\u9632\u6b62\u5916\u90e8 new<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 2. \u5185\u90e8\u521b\u5efa\u9759\u6001\u5b9e\u4f8b<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">Singleton<\/span> INSTANCE <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 3. \u63d0\u4f9b\u9759\u6001\u83b7\u53d6\u65b9\u6cd5<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token function\">getInstance<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> INSTANCE<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u5199\u6cd5\u7b80\u5355&#xff0c;\u7c7b\u52a0\u8f7d\u65f6\u5b8c\u6210\u5b9e\u4f8b\u5316&#xff0c;\u5929\u7136\u7ebf\u7a0b\u5b89\u5168&#xff08;\u7531 JVM \u4fdd\u8bc1&#xff09;\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u6ca1\u6709\u8fbe\u5230\u61d2\u52a0\u8f7d&#xff08;Lazy Loading&#xff09;\u7684\u6548\u679c\u3002\u5982\u679c\u8be5\u5b9e\u4f8b\u5f88\u5927\u4e14\u4e00\u76f4\u6ca1\u88ab\u4f7f\u7528&#xff0c;\u4f1a\u9020\u6210\u5185\u5b58\u6d6a\u8d39\u3002<\/li>\n<\/ul>\n<h3>2. \u61d2\u6c49\u5f0f&#xff08;\u7ebf\u7a0b\u4e0d\u5b89\u5168 -&gt; \u7ebf\u7a0b\u5b89\u5168&#xff09;<\/h3>\n<p>\u201c\u61d2\u6c49\u201d\u6307\u7684\u662f&#xff1a;\u53ea\u6709\u5728\u7b2c\u4e00\u6b21\u8c03\u7528 getInstance \u65f6\u624d\u4f1a\u53bb\u521b\u5efa\u5b9e\u4f8b\u3002<\/p>\n<p>\u7ebf\u7a0b\u4e0d\u5b89\u5168\u7248<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">Singleton<\/span> instance<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token function\">getInstance<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>instance <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/\/ \u591a\u7ebf\u7a0b\u73af\u5883\u4e0b&#xff0c;\u53ef\u80fd\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8fdb\u5165\u8fd9\u4e2a\u5224\u65ad<\/span><br \/>\n            instance <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> instance<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u95ee\u9898&#xff1a;\u591a\u7ebf\u7a0b\u5e76\u53d1\u65f6&#xff0c;\u53ef\u80fd\u4f1a\u521b\u5efa\u51fa\u591a\u4e2a\u5b9e\u4f8b&#xff0c;\u8fdd\u80cc\u5355\u4f8b\u521d\u8877\u3002<\/p>\n<p>\u540c\u6b65\u65b9\u6cd5\u7248&#xff08;\u6027\u80fd\u4f4e&#xff09;<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">synchronized<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token function\">getInstance<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/\/ \u52a0\u9501<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>instance <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        instance <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> instance<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u95ee\u9898&#xff1a;\u867d\u7136\u89e3\u51b3\u4e86\u7ebf\u7a0b\u5b89\u5168&#xff0c;\u4f46\u6bcf\u6b21\u8c03\u7528\u90fd\u8981\u52a0\u9501&#xff0c;\u6027\u80fd\u5f00\u9500\u6781\u5927\u3002<\/p>\n<h3>\u53cc\u91cd\u68c0\u67e5\u9501\u5b9a&#xff08;DCL&#xff0c;\u9762\u8bd5\u6700\u5e38\u8003&#xff09;<\/h3>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5fc5\u987b\u52a0 volatile \u5173\u952e\u5b57<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">volatile<\/span> <span class=\"token class-name\">Singleton<\/span> instance<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">Singleton<\/span> getInstance <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u7b2c\u4e00\u91cd\u68c0\u67e5&#xff1a;\u63d0\u5347\u6548\u7387&#xff0c;\u5982\u679c\u5df2\u7ecf\u521b\u5efa\u4e86\u5c31\u4e0d\u7528\u518d\u8fdb\u5165\u8be5\u540c\u6b65\u5757<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>instance <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">synchronized<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token comment\">\/\/ \u7b2c\u4e8c\u91cd\u68c0\u67e5&#xff1a;\u786e\u8ba4\u5728\u7b49\u5f85\u9501\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u6ca1\u6709\u5176\u4ed6\u7ebf\u7a0b\u521b\u5efa\u5b9e\u4f8b<\/span><br \/>\n                <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>instance <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                    instance <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token keyword\">return<\/span> instance<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8ffd\u95ee&#xff1a;\u4e3a\u4ec0\u4e48\u4e00\u5b9a\u8981\u52a0 volatile &#xff1f;<\/p>\n<p>instance &#061; new Singleton \u8fd9\u4e00\u884c\u4ee3\u7801\u5728 JVM \u4e2d\u5176\u5b9e\u5206\u4e3a\u4e09\u6b65&#xff1a;<\/p>\n<li>\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<li>\u521d\u59cb\u5316\u5bf9\u8c61\u3002<\/li>\n<li>\u5c06 instance \u6307\u5411\u5206\u914d\u7684\u5185\u5b58\u5730\u5740\u3002<\/li>\n<p>\u7531\u4e8e JVM \u7684\u6307\u4ee4\u91cd\u6392&#xff0c;\u6b65\u9aa4 2 \u548c 3 \u7684\u987a\u5e8f\u53ef\u80fd\u4f1a\u98a0\u5012\u3002\u5982\u679c\u7ebf\u7a0b A \u5148\u6267\u884c\u4e86 1 \u548c 3&#xff0c;\u6b64\u65f6 instance \u5df2\u4e0d\u4e3a null&#xff0c;\u4f46\u5bf9\u8c61\u521d\u59cb\u5316\u8fd8\u6ca1\u5b8c\u6210\u3002\u6b64\u65f6\u7ebf\u7a0b B \u8fdb\u6765&#xff0c;\u7b2c\u4e00\u91cd\u68c0\u67e5\u53d1\u73b0\u4e0d\u4e3a null&#xff0c;\u76f4\u63a5\u8fd4\u56de\u4e86\u8fd9\u4e2a\u201c\u534a\u6210\u54c1\u201d\u5bf9\u8c61&#xff0c;\u7a0b\u5e8f\u5c31\u4f1a\u62a5\u9519\u3002<\/p>\n<p>volatile \u7684\u4f5c\u7528\u5c31\u662f\u7981\u6b62\u6307\u4ee4\u91cd\u6392&#xff0c;\u786e\u4fdd\u5bf9\u8c61\u521b\u5efa\u7684\u6709\u5e8f\u6027\u3002<\/p>\n<h3>4. \u9759\u6001\u5185\u90e8\u7c7b&#xff08;\u63a8\u8350\u65b9\u6848&#xff09;<\/h3>\n<p>\u8fd9\u662f\u4e00\u79cd\u66f4\u4f18\u96c5\u7684\u5199\u6cd5&#xff0c;\u7ed3\u5408\u4e86\u997f\u6c49\u5f0f\u7684\u7ebf\u7a0b\u5b89\u5168\u548c\u61d2\u6c49\u5f0f\u7684\u61d2\u52a0\u8f7d\u4f18\u70b9\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u9759\u6001\u5185\u90e8\u7c7b\u53ea\u6709\u5728\u88ab\u8c03\u7528\u65f6\u624d\u4f1a\u88ab\u52a0\u8f7d<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SingletonHolder<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">Singleton<\/span> INSTANCE <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Singleton<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token function\">getInstance<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token class-name\">SingletonHolder<\/span><span class=\"token punctuation\">.<\/span>INSTANCE<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u539f\u7406&#xff1a;\u53ea\u6709\u5f53\u8c03\u7528 getInstance \u65b9\u6cd5\u65f6&#xff0c;\u624d\u4f1a\u88c5\u5728\u5185\u90e8\u7c7b SingletonHolder&#xff0c;\u4ece\u800c\u89e6\u53d1 INSTANCE \u7684\u5b9e\u4f8b\u5316&#xff0c;\u7531\u4e8e\u7c7b\u52a0\u8f7d\u8fc7\u7a0b\u662f\u7ebf\u7a0b\u5b89\u5168\u7684&#xff0c;\u56e0\u6b64\u8fd9\u79cd\u65b9\u6cd5\u65e2\u5b9e\u73b0\u4e86\u5ef6\u8fdf\u52a0\u8f7d&#xff0c;\u53c8\u4fdd\u8bc1\u4e86\u7ebf\u7a0b\u5b89\u5168&#xff0c;\u4ee3\u7801\u8fd8\u975e\u5e38\u7b80\u4ecb\u3002<\/p>\n<h3>\u679a\u4e3e\u5355\u4f8b&#xff08;\u6700\u5b8c\u7f8e\u7684\u65b9\u6848&#xff09;<\/h3>\n<p>\u300aEffective Java\u300b\u4f5c\u8005 Josh Bloch \u6781\u529b\u63a8\u8350\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">enum<\/span> <span class=\"token class-name\">Singleton<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    INSTANCE<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">doSomething<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Doing something&#8230;&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8c03\u7528\u65b9\u5f0f&#xff1a;Singleton.INSTANCE.doSomething&#xff1b;<\/p>\n<p>\u4e3a\u4ec0\u4e48\u6700\u597d&#xff1f;<\/p>\n<li>\u6781\u7b80&#xff1a;\u4ee3\u7801\u6700\u5c11\u3002<\/li>\n<li>\u7ebf\u7a0b\u5b89\u5168&#xff1a;\u7531\u679a\u4e3e\u7279\u6027\u4fdd\u8bc1\u3002<\/li>\n<li>\u9632\u6b62\u53cd\u5c04\u653b\u51fb&#xff1a;\u5373\u4fbf\u901a\u8fc7\u53cd\u5c04\u8c03\u7528 setAccessible(true)&#xff0c;\u4e5f\u65e0\u6cd5\u79c1\u81ea\u5b9e\u4f8b\u5316\u679a\u4e3e\u3002<\/li>\n<li>\u9632\u6b62\u5e8f\u5217\u5316\u7834\u574f&#xff1a;\u679a\u4e3e\u81ea\u5e26\u5e8f\u5217\u5316\u4fdd\u62a4&#xff0c;\u9632\u6b62\u53cd\u5e8f\u5217\u5316\u65f6\u751f\u6210\u65b0\u5b9e\u4f8b\u3002<\/li>\n<h3>\u603b\u7ed3&#xff1a;\u6211\u8be5\u9009\u54ea\u79cd&#xff1f;<\/h3>\n<table>\n<tr>\u5b9e\u73b0\u65b9\u5f0f\u61d2\u52a0\u8f7d\u7ebf\u7a0b\u5b89\u5168\u9632\u6b62\u53cd\u5c04\/\u5e8f\u5217\u5316\u653b\u51fb\u63a8\u8350\u7b49\u7ea7<\/tr>\n<tbody>\n<tr>\n<td>\u997f\u6c49\u5f0f<\/td>\n<td>\u274c<\/td>\n<td>\u2705<\/td>\n<td>\u274c<\/td>\n<td>\u2b50\u2b50<\/td>\n<\/tr>\n<tr>\n<td>DCL (\u53cc\u91cd\u68c0\u67e5)<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<td>\u274c<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u5185\u90e8\u7c7b<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<td>\u274c<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td>\n<\/tr>\n<tr>\n<td>\u679a\u4e3e<\/td>\n<td>\u274c<\/td>\n<td>\u2705<\/td>\n<td>\u2705<\/td>\n<td>\u2b50\u2b50\u2b50\u2b50\u2b50<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9762\u8bd5\u5efa\u8bae&#xff1a;<\/p>\n<ul>\n<li>\u5982\u679c\u9762\u8bd5\u5b98\u8ba9\u4f60\u5199\u4e00\u4e2a\u201c\u5b8c\u7f8e\u7684\u201d\u5355\u4f8b&#xff0c;\u76f4\u63a5\u5199 \u9759\u6001\u5185\u90e8\u7c7b \u6216 DCL&#xff08;\u8bb0\u5f97\u89e3\u91ca volatile&#xff09;\u3002<\/li>\n<li>\u5982\u679c\u9762\u8bd5\u5b98\u95ee\u201c\u54ea\u79cd\u65b9\u5f0f\u80fd\u9632\u5fa1\u53cd\u5c04\u653b\u51fb\u201d&#xff0c;\u4e00\u5b9a\u8981\u63d0\u5230 \u679a\u4e3e\u3002<\/li>\n<\/ul>\n<hr \/>\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u70b9\u8d5e\u6536\u85cf&#xff01;\u4f60\u7684\u652f\u6301\u662f\u6211\u521b\u4f5c\u7684\u6700\u5927\u52a8\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u8bd5\u5fc5\u4f1a&#xff1a;\u624b\u5199\u5355\u4f8b\u6a21\u5f0f&#xff08;\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0&#xff09;<br \/>\n\u5728\u8bbe\u8ba1\u6a21\u5f0f\u4e2d&#xff0c;\u5355\u4f8b\u6a21\u5f0f&#xff08;Singleton Pattern&#xff09; \u662f\u6700\u7b80\u5355\u4e5f\u662f\u6700\u5e38\u8003\u7684\u4e00\u79cd\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u786e\u4fdd\u4e00\u4e2a\u7c7b\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5168\u5c40\u8bbf\u95ee\u70b9\u3002<br \/>\n\u5728 Java \u540e\u7aef\u5f00\u53d1\u7684\u9762\u8bd5\u4e2d&#xff0c;\u9762\u8bd5\u5b98\u5e38\u5e38\u4f1a\u8981\u6c42\u4f60\u201c\u624b\u5199\u4e00\u4e2a\u5355\u4f8b\u201d&#xff0c;\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u8ffd\u95ee\u7ebf\u7a0b\u5b89\u5168\u3001\u6307\u4ee4\u91cd\u6392\u7b49\u95ee\u9898\u3002\u672c\u6587\u5e26\u4f60\u9010\u4e00\u51fb\u7834\u3002<br \/>\n1. \u997f\u6c49<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2246,925,176],"topic":[],"class_list":["post-76579","post","type-post","status-publish","format-standard","hentry","category-server","tag-2246","tag-925","tag-176"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/76579.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u9762\u8bd5\u5fc5\u4f1a&#xff1a;\u624b\u5199\u5355\u4f8b\u6a21\u5f0f&#xff08;\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0&#xff09; \u5728\u8bbe\u8ba1\u6a21\u5f0f\u4e2d&#xff0c;\u5355\u4f8b\u6a21\u5f0f&#xff08;Singleton Pattern&#xff09; \u662f\u6700\u7b80\u5355\u4e5f\u662f\u6700\u5e38\u8003\u7684\u4e00\u79cd\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u786e\u4fdd\u4e00\u4e2a\u7c7b\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5168\u5c40\u8bbf\u95ee\u70b9\u3002 \u5728 Java \u540e\u7aef\u5f00\u53d1\u7684\u9762\u8bd5\u4e2d&#xff0c;\u9762\u8bd5\u5b98\u5e38\u5e38\u4f1a\u8981\u6c42\u4f60\u201c\u624b\u5199\u4e00\u4e2a\u5355\u4f8b\u201d&#xff0c;\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u8ffd\u95ee\u7ebf\u7a0b\u5b89\u5168\u3001\u6307\u4ee4\u91cd\u6392\u7b49\u95ee\u9898\u3002\u672c\u6587\u5e26\u4f60\u9010\u4e00\u51fb\u7834\u3002 1. \u997f\u6c49\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76579.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-22T13:09:24+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76579.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76579.html\",\"name\":\"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-22T13:09:24+00:00\",\"dateModified\":\"2026-02-22T13:09:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76579.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76579.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76579.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/76579.html","og_locale":"zh_CN","og_type":"article","og_title":"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u9762\u8bd5\u5fc5\u4f1a&#xff1a;\u624b\u5199\u5355\u4f8b\u6a21\u5f0f&#xff08;\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0&#xff09; \u5728\u8bbe\u8ba1\u6a21\u5f0f\u4e2d&#xff0c;\u5355\u4f8b\u6a21\u5f0f&#xff08;Singleton Pattern&#xff09; \u662f\u6700\u7b80\u5355\u4e5f\u662f\u6700\u5e38\u8003\u7684\u4e00\u79cd\u3002\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u662f&#xff1a;\u786e\u4fdd\u4e00\u4e2a\u7c7b\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5e76\u63d0\u4f9b\u4e00\u4e2a\u5168\u5c40\u8bbf\u95ee\u70b9\u3002 \u5728 Java \u540e\u7aef\u5f00\u53d1\u7684\u9762\u8bd5\u4e2d&#xff0c;\u9762\u8bd5\u5b98\u5e38\u5e38\u4f1a\u8981\u6c42\u4f60\u201c\u624b\u5199\u4e00\u4e2a\u5355\u4f8b\u201d&#xff0c;\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u8ffd\u95ee\u7ebf\u7a0b\u5b89\u5168\u3001\u6307\u4ee4\u91cd\u6392\u7b49\u95ee\u9898\u3002\u672c\u6587\u5e26\u4f60\u9010\u4e00\u51fb\u7834\u3002 1. \u997f\u6c49","og_url":"https:\/\/www.wsisp.com\/helps\/76579.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-22T13:09:24+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76579.html","url":"https:\/\/www.wsisp.com\/helps\/76579.html","name":"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-22T13:09:24+00:00","dateModified":"2026-02-22T13:09:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76579.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76579.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76579.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u9762\u8bd5\u5fc5\u4f1a\uff1a\u624b\u5199\u5355\u4f8b\u6a21\u5f0f\uff08\u4ece\u96f6\u5230\u5b8c\u7f8e\u7684\u4e94\u79cd\u5b9e\u73b0\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76579"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76579\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76579"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}