{"id":195187,"date":"2024-11-13T12:56:23","date_gmt":"2024-11-13T04:56:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/195187\/"},"modified":"2024-11-13T12:56:25","modified_gmt":"2024-11-13T04:56:25","slug":"%e5%84%aa%e5%8c%96%e5%a4%9a%e7%b7%9a%e7%a8%8b%e6%96%b9%e5%bc%8f%e6%8f%90%e9%ab%98%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e9%80%9f%e5%ba%a6-%e5%a4%9a%e7%b7%9a%e7%a8%8b-%e6%95%b8%e6%93%9a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/195187\/","title":{"rendered":"\u512a\u5316\u591a\u7dda\u7a0b\u65b9\u5f0f\u63d0\u9ad8\u6578\u64da\u5eab\u9023\u63a5\u901f\u5ea6 (\u591a\u7dda\u7a0b \u6578\u64da\u5eab\u9023\u63a5)"},"content":{"rendered":"<h1 id=\"%e5%84%aa%e5%8c%96%e5%a4%9a%e7%b7%9a%e7%a8%8b%e6%96%b9%e5%bc%8f%e6%8f%90%e9%ab%98%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e9%80%9f%e5%ba%a6-NnLeULgrDa\">\u512a\u5316\u591a\u7dda\u7a0b\u65b9\u5f0f\u63d0\u9ad8\u6578\u64da\u5eab\u9023\u63a5\u901f\u5ea6<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6574\u9ad4\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u7528\u6236\u9700\u6c42\u7684\u589e\u52a0\uff0c\u5982\u4f55\u512a\u5316\u6578\u64da\u5eab\u9023\u63a5\u901f\u5ea6\u6210\u70ba\u4e86\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002\u591a\u7dda\u7a0b\u6280\u8853\u4f5c\u70ba\u4e00\u7a2e\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u9023\u63a5\u901f\u5ea6\u548c\u8655\u7406\u80fd\u529b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%a4%9a%e7%b7%9a%e7%a8%8b%ef%bc%9f-NnLeULgrDa\">\u4ec0\u9ebc\u662f\u591a\u7dda\u7a0b\uff1f<\/h2>\n<p>\u591a\u7dda\u7a0b\u662f\u6307\u5728\u540c\u4e00\u9032\u7a0b\u4e2d\u540c\u6642\u57f7\u884c\u591a\u500b\u7dda\u7a0b\u7684\u6280\u8853\u3002\u6bcf\u500b\u7dda\u7a0b\u53ef\u4ee5\u7368\u7acb\u57f7\u884c\u4efb\u52d9\uff0c\u9019\u6a23\u53ef\u4ee5\u5145\u5206\u5229\u7528\u591a\u6838\u8655\u7406\u5668\u7684\u8a08\u7b97\u80fd\u529b\u3002\u5c0d\u65bc\u6578\u64da\u5eab\u64cd\u4f5c\u4f86\u8aaa\uff0c\u591a\u7dda\u7a0b\u53ef\u4ee5\u540c\u6642\u8655\u7406\u591a\u500b\u8acb\u6c42\uff0c\u5f9e\u800c\u6e1b\u5c11\u7b49\u5f85\u6642\u9593\uff0c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87%e5%a4%9a%e7%b7%9a%e7%a8%8b%e4%be%86%e5%84%aa%e5%8c%96%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%ef%bc%9f-NnLeULgrDa\">\u70ba\u4ec0\u9ebc\u9078\u64c7\u591a\u7dda\u7a0b\u4f86\u512a\u5316\u6578\u64da\u5eab\u9023\u63a5\uff1f<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u4e26\u767c\u6027\uff1a<\/strong>\u591a\u7dda\u7a0b\u5141\u8a31\u591a\u500b\u8acb\u6c42\u540c\u6642\u9032\u884c\uff0c\u9019\u5c0d\u65bc\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u7a0b\u5e8f\u5c24\u70ba\u91cd\u8981\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u5ef6\u9072\uff1a<\/strong>\u901a\u904e\u540c\u6642\u8655\u7406\u591a\u500b\u8acb\u6c42\uff0c\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u7528\u6236\u7684\u7b49\u5f85\u6642\u9593\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u5229\u7528\u7387\uff1a<\/strong>\u591a\u7dda\u7a0b\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5229\u7528\u7cfb\u7d71\u8cc7\u6e90\uff0c\u7279\u5225\u662f\u5728\u591a\u6838\u8655\u7406\u5668\u4e0a\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%be%e5%a4%9a%e7%b7%9a%e7%a8%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-NnLeULgrDa\">\u5982\u4f55\u5be6\u73fe\u591a\u7dda\u7a0b\u6578\u64da\u5eab\u9023\u63a5<\/h2>\n<p>\u5be6\u73fe\u591a\u7dda\u7a0b\u6578\u64da\u5eab\u9023\u63a5\u7684\u904e\u7a0b\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e9%81%b8%e6%93%87%e5%90%88%e9%81%a9%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e9%a9%85%e5%8b%95-NnLeULgrDa\">1. \u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u9a45\u52d5<\/h3>\n<p>\u9996\u5148\uff0c\u9078\u64c7\u652f\u6301\u591a\u7dda\u7a0b\u7684\u6578\u64da\u5eab\u9a45\u52d5\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4f8b\u5982\uff0cJava\u7684JDBC\u9a45\u52d5\u548cPython\u7684SQLAlchemy\u90fd\u652f\u6301\u591a\u7dda\u7a0b\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"2-%e8%a8%ad%e7%bd%ae%e9%80%a3%e6%8e%a5%e6%b1%a0-NnLeULgrDa\">2. \u8a2d\u7f6e\u9023\u63a5\u6c60<\/h3>\n<p>\u9023\u63a5\u6c60\u662f\u4e00\u7a2e\u7ba1\u7406\u6578\u64da\u5eab\u9023\u63a5\u7684\u6280\u8853\uff0c\u53ef\u4ee5\u91cd\u7528\u73fe\u6709\u7684\u9023\u63a5\uff0c\u5f9e\u800c\u6e1b\u5c11\u9023\u63a5\u7684\u958b\u92b7\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Java\u7684HikariCP\u9023\u63a5\u6c60\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nHikariConfig config = new HikariConfig();\nconfig.setJdbcUrl(\"jdbc:mysql:\/\/localhost:3306\/mydb\");\nconfig.setUsername(\"user\");\nconfig.setPassword(\"password\");\nHikariDataSource dataSource = new HikariDataSource(config);\n<\/code><\/pre>\n<h3 id=\"3-%e5%af%a6%e7%8f%be%e5%a4%9a%e7%b7%9a%e7%a8%8b%e8%ab%8b%e6%b1%82-NnLeULgrDa\">3. \u5be6\u73fe\u591a\u7dda\u7a0b\u8acb\u6c42<\/h3>\n<p>\u5728\u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7dda\u7a0b\u4f86\u767c\u9001\u6578\u64da\u5eab\u8acb\u6c42\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Java\u7684ExecutorService\u4f86\u5be6\u73fe\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nExecutorService executor = Executors.newFixedThreadPool(10);\nfor (int i = 0; i  {\n        try (Connection connection = dataSource.getConnection()) {\n            \/\/ \u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    });\n}\nexecutor.shutdown();\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-NnLeULgrDa\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u5be6\u73fe\u591a\u7dda\u7a0b\u6578\u64da\u5eab\u9023\u63a5\u6642\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u78ba\u4fdd\u5728\u591a\u7dda\u7a0b\u74b0\u5883\u4e2d\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u907f\u514d\u7af6\u722d\u689d\u4ef6\u3002<\/li>\n<li><strong>\u9023\u63a5\u6578\u9650\u5236\uff1a<\/strong>\u6839\u64da\u6578\u64da\u5eab\u7684\u914d\u7f6e\uff0c\u8a2d\u7f6e\u5408\u7406\u7684\u6700\u5927\u9023\u63a5\u6578\uff0c\u4ee5\u9632\u6b62\u904e\u8f09\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u5728\u591a\u7dda\u7a0b\u74b0\u5883\u4e2d\uff0c\u932f\u8aa4\u8655\u7406\u5c24\u70ba\u91cd\u8981\uff0c\u61c9\u8a72\u59a5\u5584\u8655\u7406\u7570\u5e38\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-NnLeULgrDa\">\u7d50\u8ad6<\/h2>\n<p>\u901a\u904e\u512a\u5316\u591a\u7dda\u7a0b\u65b9\u5f0f\u4f86\u63d0\u9ad8\u6578\u64da\u5eab\u9023\u63a5\u901f\u5ea6\uff0c\u4e0d\u50c5\u80fd\u5920\u63d0\u5347\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\uff0c\u9084\u80fd\u6539\u5584\u7528\u6236\u9ad4\u9a57\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u958b\u767c\u8005\u958b\u59cb\u63a1\u7528\u9019\u7a2e\u65b9\u6cd5\u4f86\u61c9\u5c0d\u9ad8\u4e26\u767c\u7684\u6311\u6230\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u548c\u9023\u63a5\u6c60\u914d\u7f6e\u662f\u6210\u529f\u7684\u95dc\u9375\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\u4f86\u652f\u6301\u60a8\u7684\u591a\u7dda\u7a0b\u6578\u64da\u5eab\u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u5be6\u73fe\u6700\u4f73\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u901a\u904e\u512a\u5316\u591a\u7dda\u7a0b\u65b9\u5f0f\u63d0\u5347\u6578\u64da\u5eab\u9023\u63a5\u901f\u5ea6\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u8655\u7406\u8207\u6027\u80fd\u589e\u5f37\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-195187","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195187","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=195187"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195187\/revisions"}],"predecessor-version":[{"id":195188,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195187\/revisions\/195188"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=195187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=195187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=195187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}