{"id":62155,"date":"2024-10-13T16:38:16","date_gmt":"2024-10-13T08:38:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/62155\/"},"modified":"2024-10-13T16:38:16","modified_gmt":"2024-10-13T08:38:16","slug":"jfinal%e5%af%a6%e6%99%82%e7%9b%a3%e6%8e%a7%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%ef%bc%8c%e8%bc%95%e9%ac%86%e8%a7%a3%e6%b1%ba%e9%80%a3%e6%8e%a5%e5%95%8f%e9%a1%8c-jfinal%e7%9b%a3%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/62155\/","title":{"rendered":"Jfinal\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\uff0c\u8f15\u9b06\u89e3\u6c7a\u9023\u63a5\u554f\u984c (jfinal\u76e3\u63a7\u6578\u64da\u5eab\u7684\u9023\u63a5)"},"content":{"rendered":"<h1 id=\"jfinal%e5%af%a6%e6%99%82%e7%9b%a3%e6%8e%a7%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%ef%bc%8c%e8%bc%95%e9%ac%86%e8%a7%a3%e6%b1%ba%e9%80%a3%e6%8e%a5%e5%95%8f%e9%a1%8c-ZlctFyIdAb\">Jfinal\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\uff0c\u8f15\u9b06\u89e3\u6c7a\u9023\u63a5\u554f\u984c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7a69\u5b9a\u6027\u548c\u9023\u63a5\u7684\u53ef\u9760\u6027\u81f3\u95dc\u91cd\u8981\u3002Jfinal\u4f5c\u70ba\u4e00\u500b\u8f15\u91cf\u7d1a\u7684Java Web\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u7c21\u55ae\u800c\u5f37\u5927\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u529f\u80fd\u3002\u7136\u800c\uff0c\u96a8\u8457\u61c9\u7528\u7684\u589e\u9577\uff0c\u6578\u64da\u5eab\u9023\u63a5\u554f\u984c\u53ef\u80fd\u6703\u983b\u7e41\u51fa\u73fe\uff0c\u9019\u6642\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\u5c31\u986f\u5f97\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e7%9b%a3%e6%8e%a7%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%ef%bc%9f-ZlctFyIdAb\">\u70ba\u4ec0\u9ebc\u9700\u8981\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u554f\u984c\u53ef\u80fd\u5c0e\u81f4\u61c9\u7528\u6027\u80fd\u4e0b\u964d\uff0c\u751a\u81f3\u9020\u6210\u670d\u52d9\u4e2d\u65b7\u3002\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\u53ef\u4ee5\u53ca\u6642\u767c\u73fe\u554f\u984c\uff0c\u4e26\u63a1\u53d6\u76f8\u61c9\u7684\u63aa\u65bd\u4f86\u89e3\u6c7a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6578\u64da\u5eab\u9023\u63a5\u554f\u984c\uff1a<\/p>\n<ul>\n<li>\u9023\u63a5\u6578\u904e\u591a\uff1a\u7576\u540c\u6642\u9023\u63a5\u6578\u8d85\u904e\u6578\u64da\u5eab\u7684\u6700\u5927\u9023\u63a5\u6578\u6642\uff0c\u65b0\u7684\u9023\u63a5\u8acb\u6c42\u5c07\u88ab\u62d2\u7d55\u3002<\/li>\n<li>\u9023\u63a5\u8d85\u6642\uff1a\u5982\u679c\u9023\u63a5\u9577\u6642\u9593\u672a\u4f7f\u7528\uff0c\u53ef\u80fd\u6703\u88ab\u6578\u64da\u5eab\u81ea\u52d5\u95dc\u9589\u3002<\/li>\n<li>\u9023\u63a5\u6cc4\u6f0f\uff1a\u61c9\u7528\u672a\u6b63\u78ba\u95dc\u9589\u9023\u63a5\uff0c\u5c0e\u81f4\u53ef\u7528\u9023\u63a5\u6578\u6e1b\u5c11\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8jfinal%e4%b8%ad%e5%af%a6%e6%99%82%e7%9b%a3%e6%8e%a7%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-ZlctFyIdAb\">\u5982\u4f55\u5728Jfinal\u4e2d\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5<\/h2>\n<p>\u5728Jfinal\u4e2d\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u5e7e\u7a2e\u65b9\u5f0f\u4f86\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u7684\u5be6\u6642\u76e3\u63a7\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8jmx%e7%9b%a3%e6%8e%a7-ZlctFyIdAb\">1. \u4f7f\u7528JMX\u76e3\u63a7<\/h3>\n<p>Java Management Extensions (JMX) \u662f\u4e00\u7a2e\u7528\u65bc\u76e3\u63a7\u548c\u7ba1\u7406Java\u61c9\u7528\u7a0b\u5e8f\u7684\u6280\u8853\u3002\u901a\u904eJMX\uff0c\u53ef\u4ee5\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u72c0\u614b\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5728Jfinal\u4e2d\u555f\u7528JMX\u76e3\u63a7\u7684\u6b65\u9a5f\uff1a<\/p>\n<pre><code>\nimport com.jfinal.plugin.activerecord.ActiveRecordPlugin;\nimport com.jfinal.plugin.activerecord.dialect.MySqlDialect;\n\npublic class App {\n    public static void main(String[] args) {\n        ActiveRecordPlugin arp = new ActiveRecordPlugin(\"myDataSource\");\n        arp.setDialect(new MySqlDialect());\n        arp.start();\n        \n        \/\/ \u555f\u7528JMX\n        arp.setJmxEnabled(true);\n    }\n}\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e6%b1%a0%e7%9a%84%e7%9b%a3%e6%8e%a7%e5%8a%9f%e8%83%bd-ZlctFyIdAb\">2. \u4f7f\u7528\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u76e3\u63a7\u529f\u80fd<\/h3>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u9023\u63a5\u6c60\uff08\u5982HikariCP\u3001C3P0\u7b49\uff09\u90fd\u63d0\u4f9b\u4e86\u5167\u5efa\u7684\u76e3\u63a7\u529f\u80fd\u3002\u4ee5HikariCP\u70ba\u4f8b\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u914d\u7f6e\u4f86\u555f\u7528\u76e3\u63a7\uff1a<\/p>\n<pre><code>\nimport com.zaxxer.hikari.HikariConfig;\nimport com.zaxxer.hikari.HikariDataSource;\n\npublic class App {\n    public static void main(String[] args) {\n        HikariConfig config = new HikariConfig();\n        config.setJdbcUrl(\"jdbc:mysql:\/\/localhost:3306\/mydb\");\n        config.setUsername(\"user\");\n        config.setPassword(\"password\");\n        \n        \/\/ \u555f\u7528\u76e3\u63a7\n        config.setMetricRegistry(new com.codahale.metrics.MetricRegistry());\n        \n        HikariDataSource ds = new HikariDataSource(config);\n    }\n}\n<\/code><\/pre>\n<h3 id=\"3-%e8%87%aa%e5%ae%9a%e7%be%a9%e7%9b%a3%e6%8e%a7%e9%82%8f%e8%bc%af-ZlctFyIdAb\">3. \u81ea\u5b9a\u7fa9\u76e3\u63a7\u908f\u8f2f<\/h3>\n<p>\u9664\u4e86\u4f7f\u7528\u73fe\u6709\u7684\u76e3\u63a7\u5de5\u5177\u5916\uff0c\u958b\u767c\u8005\u9084\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u76e3\u63a7\u908f\u8f2f\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5b9a\u671f\u6aa2\u67e5\u7576\u524d\u7684\u9023\u63a5\u6578\u548c\u6700\u5927\u9023\u63a5\u6578\uff0c\u4e26\u8a18\u9304\u5230\u65e5\u8a8c\u4e2d\uff1a<\/p>\n<pre><code>\nimport java.sql.Connection;\nimport java.sql.SQLException;\n\npublic class ConnectionMonitor {\n    public static void monitorConnections(DataSource dataSource) {\n        try (Connection conn = dataSource.getConnection()) {\n            \/\/ \u7372\u53d6\u7576\u524d\u9023\u63a5\u6578\n            int currentConnections = \/\/ \u53d6\u5f97\u7576\u524d\u9023\u63a5\u6578\u7684\u908f\u8f2f\n            int maxConnections = \/\/ \u53d6\u5f97\u6700\u5927\u9023\u63a5\u6578\u7684\u908f\u8f2f\n            \n            System.out.println(\"\u7576\u524d\u9023\u63a5\u6578: \" + currentConnections);\n            System.out.println(\"\u6700\u5927\u9023\u63a5\u6578: \" + maxConnections);\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-ZlctFyIdAb\">\u7d50\u8ad6<\/h2>\n<p>\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\u662f\u78ba\u4fdd\u61c9\u7528\u7a69\u5b9a\u904b\u884c\u7684\u91cd\u8981\u63aa\u65bd\u3002\u901a\u904e\u4f7f\u7528JMX\u3001\u6578\u64da\u5eab\u9023\u63a5\u6c60\u7684\u76e3\u63a7\u529f\u80fd\u4ee5\u53ca\u81ea\u5b9a\u7fa9\u76e3\u63a7\u908f\u8f2f\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u53ca\u6642\u767c\u73fe\u4e26\u89e3\u6c7a\u9023\u63a5\u554f\u984c\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u61c9\u7528\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\uff0c\u4ee5\u78ba\u4fdd\u60a8\u7684\u6578\u64da\u5eab\u9023\u63a5\u7a69\u5b9a\u4e14\u9ad8\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JFinal\u5be6\u6642\u76e3\u63a7\u6578\u64da\u5eab\u9023\u63a5\uff0c\u5feb\u901f\u8b58\u5225\u4e26\u89e3\u6c7a\u9023\u63a5\u554f\u984c\uff0c\u78ba\u4fdd\u7cfb\u7d71\u7a69\u5b9a\u904b\u884c\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-62155","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62155","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=62155"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62155\/revisions"}],"predecessor-version":[{"id":62156,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62155\/revisions\/62156"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=62155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=62155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=62155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}