{"id":180654,"date":"2024-11-09T12:04:18","date_gmt":"2024-11-09T04:04:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/180654\/"},"modified":"2024-11-09T12:04:19","modified_gmt":"2024-11-09T04:04:19","slug":"%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e4%bd%9c%e7%94%a8%e5%92%8c%e5%8e%9f%e7%90%86%e8%a7%a3%e6%9e%90-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/180654\/","title":{"rendered":"\u6df1\u5165\u4e86\u89e3\uff1a\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u4f5c\u7528\u548c\u539f\u7406\u89e3\u6790 (\u6578\u64da\u5eab\u9023\u63a5\u6c60\u662f\u5e79\u561b\u7684)"},"content":{"rendered":"<h1 id=\"%e6%b7%b1%e5%85%a5%e4%ba%86%e8%a7%a3%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e4%bd%9c%e7%94%a8%e5%92%8c%e5%8e%9f%e7%90%86%e8%a7%a3%e6%9e%90-voCfRlaVsq\">\u6df1\u5165\u4e86\u89e3\uff1a\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u4f5c\u7528\u548c\u539f\u7406\u89e3\u6790<\/h1>\n<p>\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5f0f\u7684\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002\u7121\u8ad6\u662f\u7db2\u7ad9\u3001\u79fb\u52d5\u61c9\u7528\u9084\u662f\u4f01\u696d\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u7d44\u6210\u90e8\u5206\u3002\u7136\u800c\uff0c\u76f4\u63a5\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\u5f80\u5f80\u6703\u5e36\u4f86\u6027\u80fd\u74f6\u9838\uff0c\u9019\u5c31\u662f\u6578\u64da\u5eab\u9023\u63a5\u6c60\u51fa\u73fe\u7684\u539f\u56e0\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u4f5c\u7528\u53ca\u5176\u5de5\u4f5c\u539f\u7406\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%ef%bc%9f-voCfRlaVsq\">\u4ec0\u9ebc\u662f\u6578\u64da\u5eab\u9023\u63a5\u6c60\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u6c60\u662f\u4e00\u7a2e\u7528\u65bc\u7ba1\u7406\u6578\u64da\u5eab\u9023\u63a5\u7684\u6280\u8853\u3002\u5b83\u7684\u4e3b\u8981\u76ee\u7684\u662f\u91cd\u7528\u5df2\u5efa\u7acb\u7684\u6578\u64da\u5eab\u9023\u63a5\uff0c\u4ee5\u6e1b\u5c11\u6bcf\u6b21\u8acb\u6c42\u6642\u6240\u9700\u7684\u9023\u63a5\u958b\u92b7\u3002\u7576\u61c9\u7528\u7a0b\u5f0f\u9700\u8981\u8a2a\u554f\u6578\u64da\u5eab\u6642\uff0c\u5b83\u53ef\u4ee5\u5f9e\u9023\u63a5\u6c60\u4e2d\u7372\u53d6\u4e00\u500b\u53ef\u7528\u7684\u9023\u63a5\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u90fd\u5275\u5efa\u65b0\u7684\u9023\u63a5\u3002\u9019\u6a23\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6027\u80fd\uff0c\u9084\u6e1b\u5c11\u4e86\u8cc7\u6e90\u7684\u6d88\u8017\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-voCfRlaVsq\">\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u5de5\u4f5c\u539f\u7406\u53ef\u4ee5\u5206\u70ba\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li><strong>\u521d\u59cb\u5316\u9023\u63a5\u6c60\uff1a<\/strong>\u5728\u61c9\u7528\u7a0b\u5f0f\u555f\u52d5\u6642\uff0c\u9023\u63a5\u6c60\u6703\u5275\u5efa\u4e00\u5b9a\u6578\u91cf\u7684\u6578\u64da\u5eab\u9023\u63a5\u4e26\u5c07\u5176\u653e\u5165\u6c60\u4e2d\uff0c\u9019\u4e9b\u9023\u63a5\u6703\u4fdd\u6301\u5728\u7a7a\u9592\u72c0\u614b\uff0c\u96a8\u6642\u53ef\u4ee5\u88ab\u8acb\u6c42\u3002<\/li>\n<li><strong>\u8acb\u6c42\u9023\u63a5\uff1a<\/strong>\u7576\u61c9\u7528\u7a0b\u5f0f\u9700\u8981\u8a2a\u554f\u6578\u64da\u5eab\u6642\uff0c\u5b83\u6703\u5411\u9023\u63a5\u6c60\u8acb\u6c42\u4e00\u500b\u9023\u63a5\u3002\u5982\u679c\u6c60\u4e2d\u6709\u53ef\u7528\u7684\u9023\u63a5\uff0c\u5247\u76f4\u63a5\u8fd4\u56de\uff1b\u5982\u679c\u6c92\u6709\uff0c\u5247\u6839\u64da\u914d\u7f6e\u5275\u5efa\u65b0\u7684\u9023\u63a5\uff08\u4f46\u9019\u901a\u5e38\u662f\u6709\u9650\u5236\u7684\uff09\u3002<\/li>\n<li><strong>\u4f7f\u7528\u9023\u63a5\uff1a<\/strong>\u61c9\u7528\u7a0b\u5f0f\u4f7f\u7528\u7372\u53d6\u7684\u9023\u63a5\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u5b8c\u6210\u5f8c\u4e0d\u6703\u95dc\u9589\u9023\u63a5\uff0c\u800c\u662f\u5c07\u5176\u6b78\u9084\u7d66\u9023\u63a5\u6c60\u3002<\/li>\n<li><strong>\u6b78\u9084\u9023\u63a5\uff1a<\/strong>\u7576\u61c9\u7528\u7a0b\u5f0f\u5b8c\u6210\u6578\u64da\u5eab\u64cd\u4f5c\u5f8c\uff0c\u9023\u63a5\u6703\u88ab\u6b78\u9084\u5230\u9023\u63a5\u6c60\u4e2d\uff0c\u9019\u6a23\u53ef\u4ee5\u4f9b\u5176\u4ed6\u8acb\u6c42\u91cd\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e5%84%aa%e5%8b%a2-voCfRlaVsq\">\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528\u6578\u64da\u5eab\u9023\u63a5\u6c60\u6709\u591a\u500b\u512a\u52e2\uff1a<\/p>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>\u91cd\u7528\u9023\u63a5\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u9023\u63a5\u5efa\u7acb\u548c\u95dc\u9589\u7684\u6642\u9593\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7a0b\u5f0f\u7684\u6574\u9ad4\u6027\u80fd\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u7ba1\u7406\uff1a<\/strong>\u901a\u904e\u9650\u5236\u540c\u6642\u6253\u958b\u7684\u9023\u63a5\u6578\u91cf\uff0c\u9023\u63a5\u6c60\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u6578\u64da\u5eab\u8cc7\u6e90\uff0c\u9632\u6b62\u904e\u8f09\u3002<\/li>\n<li><strong>\u7c21\u5316\u4ee3\u78bc\uff1a<\/strong>\u958b\u767c\u8005\u4e0d\u9700\u8981\u6bcf\u6b21\u90fd\u8655\u7406\u9023\u63a5\u7684\u5efa\u7acb\u548c\u95dc\u9589\uff0c\u9019\u4f7f\u5f97\u4ee3\u78bc\u66f4\u52a0\u7c21\u6f54\u548c\u6613\u65bc\u7dad\u8b77\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e5%af%a6%e7%8f%be%e7%a4%ba%e4%be%8b-voCfRlaVsq\">\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u5be6\u73fe\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u6578\u64da\u5eab\u9023\u63a5\u6c60\u5be6\u73fe\u793a\u4f8b\uff0c\u4f7f\u7528 Java \u8a9e\u8a00\u548c JDBC\uff1a<\/p>\n<pre><code>\nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.SQLException;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class ConnectionPool {\n    private List&lt;Connection&gt; connectionPool = new ArrayList&lt;&gt;();\n    private final int MAX_CONNECTIONS = 10;\n\n    public ConnectionPool() throws SQLException {\n        for (int i = 0; i &lt; MAX_CONNECTIONS; i++) {\n            Connection connection = DriverManager.getConnection(\"jdbc:mysql:\/\/localhost:3306\/mydb\", \"user\", \"password\");\n            connectionPool.add(connection);\n        }\n    }\n\n    public synchronized Connection getConnection() {\n        if (connectionPool.size() &gt; 0) {\n            return connectionPool.remove(0);\n        }\n        return null; \/\/ \u6216\u8005\u53ef\u4ee5\u9078\u64c7\u5275\u5efa\u65b0\u7684\u9023\u63a5\n    }\n\n    public synchronized void returnConnection(Connection connection) {\n        connectionPool.add(connection);\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-voCfRlaVsq\">\u7d50\u8ad6<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u6c60\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5f0f\u4e2d\u626e\u6f14\u8457\u81f3\u95dc\u91cd\u8981\u7684\u89d2\u8272\u3002\u5b83\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6027\u80fd\uff0c\u9084\u6709\u6548\u7ba1\u7406\u4e86\u8cc7\u6e90\uff0c\u7c21\u5316\u4e86\u958b\u767c\u904e\u7a0b\u3002\u96a8\u8457\u61c9\u7528\u7a0b\u5f0f\u9700\u6c42\u7684\u589e\u9577\uff0c\u7406\u89e3\u548c\u5be6\u65bd\u6578\u64da\u5eab\u9023\u63a5\u6c60\u5c07\u6210\u70ba\u958b\u767c\u8005\u5fc5\u5099\u7684\u6280\u80fd\u4e4b\u4e00\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u4e86\u89e3\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u4f5c\u7528\u8207\u539f\u7406\uff0c\u63ed\u793a\u5176\u5982\u4f55\u63d0\u5347\u6027\u80fd\u8207\u8cc7\u6e90\u7ba1\u7406\uff0c\u8b93\u6578\u64da\u5eab\u64cd\u4f5c\u66f4\u9ad8\u6548\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-180654","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=180654"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180654\/revisions"}],"predecessor-version":[{"id":180655,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180654\/revisions\/180655"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=180654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=180654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=180654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}