{"id":97522,"date":"2026-08-29T18:56:57","date_gmt":"2026-08-29T10:56:57","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97522.html"},"modified":"2026-08-29T18:56:57","modified_gmt":"2026-08-29T10:56:57","slug":"javaee%e5%88%9d%e9%98%b6-%e5%a4%9a%e7%ba%bf%e7%a8%8b%ef%bc%9a%e5%8d%95%e4%be%8b%e6%a8%a1%e5%bc%8f-%e9%98%bb%e5%a1%9e%e9%98%9f%e5%88%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97522.html","title":{"rendered":"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:40px\">\n<p id=\"Singleton%20%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F-toc\" style=\"margin-left:40px\">Singleton \u5355\u4f8b\u6a21\u5f0f<\/p>\n<p id=\"%E9%A5%BF%E6%B1%89%E6%A8%A1%E5%BC%8F%EF%BC%8C%E8%BF%90%E8%A1%8C%E5%8D%B3%E5%88%9B%E5%BB%BA-toc\" style=\"margin-left:80px\">\u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa<\/p>\n<p id=\"%E6%87%92%E6%B1%89%E6%A8%A1%E5%BC%8F%EF%BC%8C%E9%9C%80%E8%A6%81%E6%97%B6%E5%86%8D%E5%88%9B%E5%BB%BA-toc\" style=\"margin-left:80px\">\u61d2\u6c49\u6a21\u5f0f&#xff0c;\u9700\u8981\u65f6\u518d\u521b\u5efa<\/p>\n<p id=\"%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:80px\">\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<\/p>\n<p id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97-toc\" style=\"margin-left:40px\">\u963b\u585e\u961f\u5217<\/p>\n<p id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:80px\">\u963b\u585e\u961f\u5217\u5b9e\u73b0<\/p>\n<p id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E4%BD%BF%E7%94%A8-toc\" style=\"margin-left:80px\">\u963b\u585e\u961f\u5217\u7684\u4f7f\u7528<\/p>\n<p id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E4%BD%9C%E7%94%A8-toc\" style=\"margin-left:80px\">\u963b\u585e\u961f\u5217\u4f5c\u7528<\/p>\n<hr id=\"hr-toc\" \/>\n<h3 id=\"Singleton%20%E5%8D%95%E4%BE%8B%E6%A8%A1%E5%BC%8F\">Singleton \u5355\u4f8b\u6a21\u5f0f<\/h3>\n<p>\u5355\u4f8b\u6a21\u5f0f\u80fd\u4fdd\u8bc1<span style=\"color:#fe2c24\">\u67d0\u4e2a\u7c7b\u5728\u7a0b\u5e8f\u4e2d\u53ea\u5b58\u5728\u552f\u2f00\u2f00\u4efd\u5b9e\u4f8b<\/span>,\u2f7d\u4e0d\u4f1a\u521b\u5efa\u51fa\u591a\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<p>\u5355\u4f8b\u6a21\u5f0f\u6700\u5e38\u2ec5\u7684\u5b9e\u73b0\u2f45\u7684\u662f&#034;\u997f\u6c49&#034;\u548c&#034;\u61d2\u6c49&#034;\u4e24\u79cd<\/p>\n<h4 id=\"%E9%A5%BF%E6%B1%89%E6%A8%A1%E5%BC%8F%EF%BC%8C%E8%BF%90%E8%A1%8C%E5%8D%B3%E5%88%9B%E5%BB%BA\">\u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa<\/h4>\n<p>class Singleton{<br \/>\n    private static Singleton instance&#061;new Singleton();<br \/>\n    private static Singleton getinstance(){<br \/>\n        return instance;<br \/>\n    }<br \/>\n    \/\/\u6784\u9020\u65b9\u6cd5\u79c1\u6709\u5316&#xff0c;\u4ec5\u9650\u5728Singleton\u7c7b\u4e2d\u5b9e\u4f8b\u5316&#xff0c;\u786e\u4fdd\u5355\u4f8b\u5316<br \/>\n    private  Singleton(){<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"%E6%87%92%E6%B1%89%E6%A8%A1%E5%BC%8F%EF%BC%8C%E9%9C%80%E8%A6%81%E6%97%B6%E5%86%8D%E5%88%9B%E5%BB%BA\">\u61d2\u6c49\u6a21\u5f0f&#xff0c;\u9700\u8981\u65f6\u518d\u521b\u5efa<\/h4>\n<p>class Singleton{<br \/>\n    private static Object locker&#061;new Object();<br \/>\n\/\/volatile\u4fee\u9970instance<br \/>\n    private static volatile Singleton instance&#061;null;<br \/>\n    public static Singleton getinstance(){<br \/>\nif (instance&#061;&#061;null){<br \/>\n    synchronized (locker){<br \/>\n        if (instance&#061;&#061;null){<br \/>\n            instance&#061;new Singleton();<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n        \/\/\u5b9e\u4f8b\u5316\u65f6\u539f\u5b50\u64cd\u4f5c<br \/>\n        return instance;<br \/>\n    }<br \/>\n    \/\/\u6784\u9020\u65b9\u6cd5\u79c1\u6709\u5316&#xff0c;\u4ec5\u9650\u5728Singleton\u7c7b\u4e2d\u5b9e\u4f8b\u5316&#xff0c;\u786e\u4fdd\u5355\u4f8b\u5316<br \/>\n    private  Singleton(){<br \/>\n    }<br \/>\n} <\/p>\n<h4 id=\"%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E9%97%AE%E9%A2%98\">\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<\/h4>\n<p>\u997f\u6c49\u6a21\u5f0f\u4e0d\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898&#xff0c;\u61d2\u6c49\u6a21\u5f0f\u5f53<span style=\"color:#fe2c24\">\u591a\u4e2a\u7ebf\u7a0b\u8c03\u7528getInstance\u2f45\u6cd5,\u5c31\u53ef\u80fd\u5bfc\u81f4\u521b\u5efa \u51fa\u591a\u4e2a\u5b9e\u4f8b&#xff0c;\u540e\u9762\u7684\u5b9e\u4f8b\u4f1a\u8986\u76d6\u524d\u9762\u5b9e\u4f8b<\/span>&#xff0c;\u8d44\u6e90\u6d6a\u8d39\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"502\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105655-6a92baf768150.png\" width=\"1131\" \/><\/p>\n<p>\u2f00\u65e6\u5b9e\u4f8b\u5df2\u7ecf\u521b\u5efa\u597d\u4e86,\u540e\u2faf\u518d\u591a\u7ebf\u7a0b\u73af\u5883\u8c03\u2f64getInstance\u5c31\u4e0d\u518d\u6709\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u4e86(\u4e0d\u518d\u4fee\u6539 instance \u4e86&#xff09;<\/p>\n<p>\u4f7f\u7528\u9501\u4fdd\u8bc1\u539f\u5b50\u6027<\/p>\n<p>\/\/\u5224\u65ad\u662f\u5426\u9700\u8981\u52a0\u9501&#xff0c;\u5df2\u7ecf\u521b\u5efa\u5b9e\u4f8b\u540e\u51cf\u5c11\u8d44\u6e90\u6d6a\u8d39<br \/>\nif (instance&#061;&#061;null){<br \/>\n    synchronized (locker){<br \/>\n\/\/\u5224\u65ad\u662f\u5426\u9700\u8981\u5b9e\u4f8b\u5316<br \/>\n        if (instance&#061;&#061;null){<br \/>\n            instance&#061;new Singleton();<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u901a\u8fc7volatile\u5173\u952e\u5b57\u4fee\u9970<\/p>\n<p>\u4f46\u7ebf\u7a0b\u5728\u52a0\u9501\u64cd\u4f5c\u65f6\u4ecd\u4f1a\u88ab\u8c03\u5ea6&#xff0c;<span style=\"color:#fe2c24\">\u5bfc\u81f4t1\u7ebf\u7a0b\u4e2dinstance\u4f7f\u7528\u4e86\u672a\u521d\u59cb\u5316\u7684\u5b9e\u4f8b<\/span>&#xff0c;\u56e0\u6b64\u9700\u8981\u52a0\u5165volatile\u907f\u514d\u91cd\u6392\u5e8f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"876\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105656-6a92baf810826.png\" width=\"1305\" \/><\/p>\n<p>\u5bf9\u6570\u636e\u5e93\u4f7f\u7528\u5355\u4f8b\u6a21\u5f0f<\/p>\n<p>class DBUtil {<br \/>\n    private static volatile DataSource dataSource &#061; null;<\/p>\n<p>    public static DataSource getInstance() {<br \/>\n        if (dataSource &#061;&#061; null) {<br \/>\n            synchronized (DBUtil.class) {<br \/>\n                if (dataSource &#061;&#061; null) {<br \/>\n                    MysqlDataSource ds &#061; new MysqlDataSource();<br \/>\n                    ds.setUrl(&#034;jdbc:mysql:\/\/127.0.0.1:3306\/java117?characterEncoding&#061;utf8&amp;useSSL&#061;false&#034;);<br \/>\n                    ds.setUser(&#034;root&#034;);<br \/>\n                    ds.setPassword(&#034;2222&#034;);<br \/>\n                    dataSource &#061; ds;<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        return dataSource;<br \/>\n    }<br \/>\n   private DBUtil{}<br \/>\n} <\/p>\n<h3 id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97\">\u963b\u585e\u961f\u5217<\/h3>\n<p>\u963b\u585e\u961f\u5217\u662f\u2f00\u79cd\u7279\u6b8a\u7684\u961f\u5217.\u4e5f\u9075\u5b88&#034;\u5148\u8fdb\u5148\u51fa&#034;\u7684\u539f\u5219&#xff0c;\u5177\u6709<span style=\"color:#fe2c24\">\u7ebf\u7a0b\u5b89\u5168<\/span>\u7684<span style=\"color:#fe2c24\">\u963b\u585e\u961f\u5217<\/span><\/p>\n<p>1.\u5f53\u961f\u5217\u6ee1\u7684\u65f6\u5019,\u7ee7\u7eed\u2f0a\u961f\u5217\u5c31\u4f1a\u963b\u585e,\u76f4\u5230\u6709\u5176\u4ed6\u7ebf\u7a0b\u4ece\u961f\u5217\u4e2d\u53d6\u2f9b\u5143\u7d20.<\/p>\n<p>\u00a02.\u5f53\u961f\u5217\u7a7a\u7684\u65f6\u5019,\u7ee7\u7eed\u51fa\u961f\u5217\u4e5f\u4f1a\u963b\u585e,\u76f4\u5230\u6709\u5176\u4ed6\u7ebf\u7a0b\u5f80\u961f\u5217\u4e2d\u63d2\u2f0a\u5143\u7d20.<\/p>\n<h4 id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0\">\u963b\u585e\u961f\u5217\u5b9e\u73b0<\/h4>\n<p>class  Queue{<br \/>\nprivate int[] Arrayqueue;<br \/>\nint tail&#061;0;<br \/>\nint head&#061;0;<br \/>\nint size&#061;0;<br \/>\npublic Queue(int capacity){<br \/>\n    Arrayqueue&#061;new int[capacity];<br \/>\n}<br \/>\nObject locker&#061;new Object();<br \/>\npublic void put(int n) throws InterruptedException {<br \/>\n    \/\/\u5224\u6ee1\u8fd4\u56de<br \/>\n    \/\/\u7ebf\u7a0b\u5b89\u5168<br \/>\n    synchronized (locker){<br \/>\n        \/*if(size&#061;&#061;Arrayqueue.length){<br \/>\n         \/\/\u963b\u585e\u7b49\u5f85<br \/>\n           locker.wait();<br \/>\n        }*\/ \/\/wait\u88ab\u5524\u9192\u65f6\u4f1a\u91cd\u65b0\u68c0\u64e6size\u662f\u5426\u7b26\u5408\u8981\u6c42<br \/>\n        while (size&#061;&#061;Arrayqueue.length){<br \/>\n           locker.wait();<br \/>\n        }<br \/>\n        Arrayqueue[head]&#061;n;<br \/>\n        head&#061;(head&#043;1)%Arrayqueue.length;<br \/>\n        size&#043;&#043;;<br \/>\n        locker.notifyAll();<br \/>\n    }<br \/>\n}<br \/>\npublic int take() throws InterruptedException {<br \/>\n    synchronized (locker){<br \/>\n        \/*if (size&#061;&#061;0){<br \/>\n            locker.wait();<br \/>\n        }*\/<br \/>\n        while (size&#061;&#061;0){<br \/>\n            locker.wait();<br \/>\n        }<br \/>\n        int n&#061; Arrayqueue[tail];<br \/>\n        tail&#061;(tail&#043;1)% Arrayqueue.length;<br \/>\n        size&#8211;;<br \/>\n        locker.notifyAll();<br \/>\n        return n;<br \/>\n    }<br \/>\n}<br \/>\n        } <\/p>\n<p>\u963b\u585e\u7684\u961f\u5217\u7684\u5e94\u7528\u573a\u666f&#xff1a;\u751f\u4ea7\u6d88\u8d39\u8005\u6a21\u578b<\/p>\n<p>\u751f\u4ea7\u8005\u7ebf\u7a0b\u7528\u6765\u751f\u4ea7&#xff0c;\u4ea7\u51fa\u653e\u5165\u963b\u585e\u961f\u5217&#xff0c;\u6d88\u8d39\u8005\u7ebf\u7a0b\u4ece\u963b\u585e\u961f\u5217\u53d6\u51fa\u4ea7\u54c1\u6d88\u8d39<\/p>\n<h4 id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E7%9A%84%E4%BD%BF%E7%94%A8\">\u963b\u585e\u961f\u5217\u7684\u4f7f\u7528<\/h4>\n<p>\u5728Java\u6807\u51c6\u5e93\u4e2d\u5185\u7f6e\u4e86\u963b\u585e\u961f\u5217.\u5982\u679c\u6211\u4eec\u9700\u8981\u5728\u2f00\u4e9b\u7a0b\u5e8f\u4e2d\u4f7f\u2f64\u963b\u585e\u961f\u5217,\u76f4\u63a5\u4f7f\u2f64\u6807\u51c6\u5e93\u4e2d\u7684\u5373 \u53ef.<\/p>\n<p>1.BlockingQueue\u662f\u2f00\u4e2a\u63a5\u2f1d.\u771f\u6b63\u5b9e\u73b0\u7c7b\u5305\u62ecLinkedBlockingQueue\/ArrayBlockingQueue\/PriorityBlockingQueue.<\/p>\n<p>2.put\u2f45\u6cd5\u2f64\u4e8e\u963b\u585e\u5f0f\u7684\u2f0a\u961f\u5217,take\u2f64\u4e8e\u963b\u585e\u5f0f\u7684\u51fa\u961f\u5217.<\/p>\n<p>3.BlockingQueue\u4e5f\u6709offer,poll,peek\u7b49\u2f45\u6cd5,\u4f46\u662f\u8fd9\u4e9b\u2f45\u6cd5\u4e0d\u5e26\u6709\u963b\u585e\u7279\u6027<\/p>\n<p>public static void main(String[] args) {<br \/>\n       \/\/ BlockingDeque&lt;Integer&gt; queue&#061;new LinkedBlockingDeque&lt;&gt;();<br \/>\n       \/\/ BlockingQueue&lt;Integer&gt; queue&#061;new ArrayBlockingQueue&lt;&gt;(100);<br \/>\n        \/\/BlockingDeque&lt;Integer&gt; queue&#061; new PriorityBlockingQueue&lt;Integer&gt;();<br \/>\n     Queue queue&#061;new Queue(100);<br \/>\nThread t0&#061;new Thread(()-&gt;{<br \/>\n     int n&#061;0;<br \/>\n     while (true){<br \/>\n         try {<br \/>\n             queue.put(n);<br \/>\n             System.out.println(&#034;\u751f\u4ea7\u4e86: &#034; &#043; n);<br \/>\n             n&#043;&#043;;<br \/>\n         } catch (InterruptedException e) {<br \/>\n             throw new RuntimeException(e);<br \/>\n         }<br \/>\n         try {<br \/>\n             Thread.sleep(1000);<br \/>\n         } catch (InterruptedException e) {<br \/>\n             throw new RuntimeException(e);<br \/>\n         }<\/p>\n<p>     }<br \/>\n});<br \/>\nThread t1&#061;new Thread(()-&gt;{<br \/>\n     \/\/int n&#061;0;<br \/>\n     while (true){<br \/>\n         \/\/int n&#061; 0;<br \/>\n         try {<br \/>\n            int n &#061; queue.take();<br \/>\n             System.out.println(&#034;\u6d88\u8d39\u4e86: &#034; &#043; n);<br \/>\n         } catch (InterruptedException e) {<br \/>\n             throw new RuntimeException(e);<br \/>\n         }<\/p>\n<p>     }<br \/>\n});<br \/>\nt0.start();<br \/>\nt1.start();<br \/>\n    }<\/p>\n<h4 id=\"%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97%E4%BD%9C%E7%94%A8\">\u963b\u585e\u961f\u5217\u4f5c\u7528<\/h4>\n<p>1.\u51cf\u5c11\u8d44\u6e90\u7ade\u4e89,\u751f\u4ea7\u6d88\u8d39\u8005\u5404\u53f8\u5176\u804c<\/p>\n<p>2.\u89e3\u8026\u5408<\/p>\n<p>\u6d4f\u89c8\u5668\u4e0b\u5355\u901a\u8fc7\u7f51\u5173\u4f20\u9012\u670d\u52a1\u5668a&#xff0c;\u518d\u901a\u8fc7\u670d\u52a1\u5668b\u5904\u7406\u8fd4\u56de&#xff0c;\u5982\u679cb\u51fa\u73b0\u95ee\u9898\u76f4\u63a5\u5f71\u54cda\u5904\u7406<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"156\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105656-6a92baf875765.png\" width=\"1009\" \/><\/p>\n<\/p>\n<p>\u901a\u8fc7\u963b\u585e\u961f\u5217 a\u4e0e\u961f\u5217\u8026\u5408&#xff0c;b\u4e0e\u961f\u5217\u8026\u5408<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"206\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105656-6a92baf890161.png\" width=\"520\" \/><\/p>\n<p>3.\u524a\u5cf0\u586b\u8c37<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"173\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105656-6a92baf8ce8d8.png\" width=\"217\" \/><\/p>\n<p>\u5f53\u67d0\u4e2a\u65f6\u95f4\u6bb5\u8bbf\u95ee\u91cf\u6fc0\u589e&#xff0c;\u963b\u585e\u961f\u5217\u4f1a\u5148\u63a5\u53d7\u8bbf\u95ee\u91cf&#xff0c;\u7b49\u5f85\u670d\u52a1\u5668\u5904\u7406&#xff0c;\u51cf\u7f13\u670d\u52a1\u5668\u538b\u529b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 Singleton \u5355\u4f8b\u6a21\u5f0f<br \/>\n\u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa<br \/>\n\u61d2\u6c49\u6a21\u5f0f&#xff0c;\u9700\u8981\u65f6\u518d\u521b\u5efa<br \/>\n\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<br \/>\n\u963b\u585e\u961f\u5217<br \/>\n\u963b\u585e\u961f\u5217\u5b9e\u73b0<br \/>\n\u963b\u585e\u961f\u5217\u7684\u4f7f\u7528<br \/>\n\u963b\u585e\u961f\u5217\u4f5c\u7528 Singleton \u5355\u4f8b\u6a21\u5f0f<br \/>\n\u5355\u4f8b\u6a21\u5f0f\u80fd\u4fdd\u8bc1\u67d0\u4e2a\u7c7b\u5728\u7a0b\u5e8f\u4e2d\u53ea\u5b58\u5728\u552f\u2f00\u2f00\u4efd\u5b9e\u4f8b,\u2f7d\u4e0d\u4f1a\u521b\u5efa\u51fa\u591a\u4e2a\u5b9e\u4f8b\u3002<br \/>\n\u5355\u4f8b\u6a21\u5f0f\u6700\u5e38\u2ec5\u7684\u5b9e\u73b0\u2f45\u7684\u662f\\&#8221;\u997f\u6c49\\&#8221;\u548c\\&#8221;\u61d2\u6c49\\&#8221;\u4e24\u79cd<br \/>\n\u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa<br \/>\nclass Singleton{private static Singleton insta<\/p>\n","protected":false},"author":2,"featured_media":97517,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-97522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \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\/97522.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 Singleton \u5355\u4f8b\u6a21\u5f0f \u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa \u61d2\u6c49\u6a21\u5f0f&#xff0c;\u9700\u8981\u65f6\u518d\u521b\u5efa \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898 \u963b\u585e\u961f\u5217 \u963b\u585e\u961f\u5217\u5b9e\u73b0 \u963b\u585e\u961f\u5217\u7684\u4f7f\u7528 \u963b\u585e\u961f\u5217\u4f5c\u7528 Singleton \u5355\u4f8b\u6a21\u5f0f \u5355\u4f8b\u6a21\u5f0f\u80fd\u4fdd\u8bc1\u67d0\u4e2a\u7c7b\u5728\u7a0b\u5e8f\u4e2d\u53ea\u5b58\u5728\u552f\u2f00\u2f00\u4efd\u5b9e\u4f8b,\u2f7d\u4e0d\u4f1a\u521b\u5efa\u51fa\u591a\u4e2a\u5b9e\u4f8b\u3002 \u5355\u4f8b\u6a21\u5f0f\u6700\u5e38\u2ec5\u7684\u5b9e\u73b0\u2f45\u7684\u662f&quot;\u997f\u6c49&quot;\u548c&quot;\u61d2\u6c49&quot;\u4e24\u79cd \u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa class Singleton{private static Singleton insta\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97522.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-29T10:56:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105655-6a92baf768150.png\" \/>\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\/97522.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97522.html\",\"name\":\"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-29T10:56:57+00:00\",\"dateModified\":\"2026-08-29T10:56:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97522.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97522.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97522.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217\"}]},{\"@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":"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \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\/97522.html","og_locale":"zh_CN","og_type":"article","og_title":"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 Singleton \u5355\u4f8b\u6a21\u5f0f \u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa \u61d2\u6c49\u6a21\u5f0f&#xff0c;\u9700\u8981\u65f6\u518d\u521b\u5efa \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898 \u963b\u585e\u961f\u5217 \u963b\u585e\u961f\u5217\u5b9e\u73b0 \u963b\u585e\u961f\u5217\u7684\u4f7f\u7528 \u963b\u585e\u961f\u5217\u4f5c\u7528 Singleton \u5355\u4f8b\u6a21\u5f0f \u5355\u4f8b\u6a21\u5f0f\u80fd\u4fdd\u8bc1\u67d0\u4e2a\u7c7b\u5728\u7a0b\u5e8f\u4e2d\u53ea\u5b58\u5728\u552f\u2f00\u2f00\u4efd\u5b9e\u4f8b,\u2f7d\u4e0d\u4f1a\u521b\u5efa\u51fa\u591a\u4e2a\u5b9e\u4f8b\u3002 \u5355\u4f8b\u6a21\u5f0f\u6700\u5e38\u2ec5\u7684\u5b9e\u73b0\u2f45\u7684\u662f\"\u997f\u6c49\"\u548c\"\u61d2\u6c49\"\u4e24\u79cd \u997f\u6c49\u6a21\u5f0f&#xff0c;\u8fd0\u884c\u5373\u521b\u5efa class Singleton{private static Singleton insta","og_url":"https:\/\/www.wsisp.com\/helps\/97522.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-29T10:56:57+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829105655-6a92baf768150.png"}],"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\/97522.html","url":"https:\/\/www.wsisp.com\/helps\/97522.html","name":"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-29T10:56:57+00:00","dateModified":"2026-08-29T10:56:57+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97522.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97522.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97522.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"JavaEE\u521d\u9636 \u591a\u7ebf\u7a0b\uff1a\u5355\u4f8b\u6a21\u5f0f | \u963b\u585e\u961f\u5217"}]},{"@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\/97522","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=97522"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97522\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/97517"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97522"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}