{"id":42405,"date":"2023-03-10T05:53:42","date_gmt":"2023-03-09T21:53:42","guid":{"rendered":"http:\/\/gulass.cn\/?p=42405"},"modified":"2023-03-10T05:53:42","modified_gmt":"2023-03-09T21:53:42","slug":"great-java-performance","status":"publish","type":"post","link":"https:\/\/gulass.cn\/great-java-performance.html","title":{"rendered":"Java \u6027\u80fd\u4f18\u5316\u7684\u4e94\u5927\u6280\u5de7"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8981\u5bf9\u4f60\u7684 java \u4ee3\u7801\u8fdb\u884c\u4f18\u5316\uff0c\u9700\u8981\u7406\u89e3 java \u4e0d\u540c\u8981\u7d20\u4e4b\u95f4\u7684\u76f8\u4e92\u4f5c\u7528\uff0c\u4ee5\u53ca\u5b83\u662f\u5982\u4f55\u4e0e\u5176\u8fd0\u884c\u65f6\u7684\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\u7684\u3002\u4f7f\u7528\u4e0b\u9762\u8fd9\u4e94\u4e2a\u6280\u5de7\u548c\u8d44\u6e90\uff0c\u5f00\u59cb\u5b66\u4e60\u5982\u4f55\u5206\u6790\u548c\u4f18\u5316\u4f60\u7684\u4ee3\u7801\u5427\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5728\u6211\u4eec\u5f00\u59cb\u4e4b\u524d, \u4f60\u4e5f\u8bb8\u4f1a\u62c5\u5fc3\u8bb8\u53ef\u7684\u95ee\u9898. Java \u4e3a Oracle \u516c\u53f8\u6240\u6709\uff0c\u9075\u5faa Oracle \u7684 BCL \u8bb8\u53ef\uff0c\u8be5\u8bb8\u53ef\u8bc1\u4e0d\u662f\u4e00\u4e2a\u514d\u8d39\/\u5f00\u6e90\u8bb8\u53ef\u8bc1\u3002\u5373\u4fbf\u5982\u6b64\uff0c\u00a0\u4ecd\u7136\u6709\u8bb8\u591a\u5f00\u6e90\u9879\u76ee\u7531 Oracle \u516c\u53f8\u7684 Java \u5f00\u53d1\u3002\u00a0OpenJDK \u662f java \u5e73\u53f0\u81ea\u7531\u8f6f\u4ef6\u7684\u5b9e\u73b0\uff0c\u9075\u5faa\u00a0GPL v2 \u8bb8\u53ef\u3002\u00a0(\u66f4\u591a\u4fe1\u606f\u8bf7\u53c2\u89c1\u7ef4\u57fa\u767e\u79d1 Free Java implementations\u3002)<\/p>\n \u8ba9\u6211\u4eec\u5f00\u59cb\u5427<\/strong><\/div>\n \u6027\u80fd\u4f18\u5316\u53d6\u51b3\u4e8e\u591a\u4e2a\u56e0\u7d20\uff0c\u5305\u62ec\u5783\u573e\u6536\u96c6\u3001\u865a\u62df\u673a\u548c\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\uff08OS\uff09\u8bbe\u7f6e\u3002\u6709\u591a\u4e2a\u5de5\u5177\u53ef\u4f9b\u5f00\u53d1\u4eba\u5458\u8fdb\u884c\u5206\u6790\u548c\u4f18\u5316\u65f6\u4f7f\u7528\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u9605\u8bfb\u00a0Java Tools for Source Code Optimization and Analysis\u00a0<\/em>\u6765\u5b66\u4e60\u548c\u4f7f\u7528\u5b83\u4eec\u3002\u5982\u679c\u4f60\u6b63\u82e6\u82e6\u6323\u624e\u4e8e\u672f\u8bed\u548c Java \u7684\u539f\u7406\uff0c\u53ef\u4ee5\u5148\u53bb\u67e5\u770b\u00a0Livecoding Java category page\uff0c\u4e0a\u9762\u6709\u76f4\u64ad\uff0c\u5b58\u6863\u7684\u89c6\u9891\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5176\u4ed6\u6709\u7528\u7684\u4fe1\u606f\u3002<\/p>\n \u5fc5\u987b\u8981\u660e\u767d\u7684\u662f\uff0c\u6ca1\u6709\u4e24\u4e2a\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u4f18\u5316\u65b9\u5f0f\uff0c\u4e5f\u6ca1\u6709\u5b8c\u7f8e\u7684\u4f18\u5316 java \u5e94\u7528\u7a0b\u5e8f\u7684\u53c2\u8003\u8def\u5f84\u3002\u4f7f\u7528\u6700\u4f73\u5b9e\u8df5\u5e76\u4e14\u575a\u6301\u91c7\u7528\u9002\u5f53\u7684\u65b9\u5f0f\u5904\u7406\u6027\u80fd\u4f18\u5316\u3002\u60f3\u8981\u8fbe\u5230\u771f\u6b63\u6700\u9ad8\u7684\u6027\u80fd\u4f18\u5316\uff0c\u4f60\u4f5c\u4e3a\u4e00\u4e2a Java \u5f00\u53d1\u4eba\u5458\uff0c\u9700\u8981\u5bf9\u00a0Java \u865a\u62df\u673a\uff08JVM\uff09\u548c\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\u6709\u6b63\u786e\u7684\u7406\u89e3\uff1a<\/p>\n \u6e05\u695a\u4e86\u6027\u80fd\u4f18\u5316\u548c\u5176\u8981\u7d20,\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u4e13\u6ce8\u4e8e\u90a3\u4e9b\u53ef\u4ee5\u4f18\u5316\u4f60\u7684Java\u5e94\u7528\u7684\u6280\u5de7\u3002<\/p>\n \u6b64\u5916,\u4f60\u8981\u660e\u767d\u5e94\u7528\u8fd0\u884c\u671f\u95f4\u6027\u80fd\u4e0b\u964d\u7684\u6548\u5e94.\u5728\u6bcf\u5355\u4e2acpu\u65f6\u949f\u5185\u7684\u7f13\u6162\u64cd\u4f5c\u662f\u53ef\u4ee5\u5ffd\u7565\u7684,\u4f46\u5728\u6bcf\u5355\u4e2a\u6570\u636e\u5e93\u4e8b\u52a1\u4e2d\u7684\u7f13\u6162\u64cd\u4f5c\u5219\u662f\u975e\u5e38\u6602\u8d35\u7684\u6d88\u8017.\u4f46\u662f\u4f60\u5e94\u8be5\u6839\u636e\u6027\u80fd\u77ed\u677f\u9009\u62e9\u4f60\u7684\u4f18\u5316\u7b56\u7565,\u5e76\u5e94\u8be5\u6839\u636e\u5de5\u4f5c\u8d1f\u8f7d\u6765\u4f18\u5316\u5e94\u7528\u3002<\/p>\n \u8ba9\u6211\u4eec\u66f4\u6df1\u5165\u5730\u63a2\u8ba8GC\u4f18\u5316.\u6bd5\u7adf,GC\u4f18\u5316\u662f\u8981\u5904\u7406\u7684\u6574\u4e2a\u4f18\u5316\u95ee\u9898\u4e2d\u6700\u57fa\u672c\u7684.\u76ee\u524d,Java\u4e2d\u6709\u56db\u79cd\u4f9b\u4f60\u9009\u62e9\u7684\u5783\u573e\u6536\u96c6\u7b97\u6cd5.\u6bcf\u79cd\u7b97\u6cd5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42,\u56e0\u6b64\u4f60\u8981\u9009\u62e9(\u9002\u5408\u4f60\u7684\u9700\u6c42\u7684).\u5f88\u591a\u5f00\u53d1\u4eba\u5458\u6b63\u662f\u56e0\u4e3a\u4e0d\u4e86\u89e3GC\u7b97\u6cd5\u800c\u672a\u80fd\u4f18\u5316\u4ed6\u4eec\u7684\u5e94\u7528\u3002<\/p>\n \u8fd9\u56db\u4e2a\u7b97\u6cd5\u5206\u522b\u662f\u4e32\u884c\u56de\u6536\u5668,\u5e76\u884c\/\u541e\u5410\u91cf\u56de\u6536\u5668,CMS\u56de\u6536\u5668\u548cG1\u56de\u6536\u5668.\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u6bcf\u79cd\u5783\u573e\u6536\u96c6\u5668\u7684\u4fe1\u606f\u53ca\u5b83\u4eec\u662f\u5982\u4f55\u5de5\u4f5c\u7684,\u8bf7\u67e5\u770b\u8fd9\u7bc7\u6765\u81eaTakipi\u535a\u5ba2\u7684\u975e\u5e38\u68d2\u7684\u6587\u7ae0Garbage Collectors\u2014Serial vs. Parallel vs. CMS vs. G1<\/em>.\u00a0 \u8fd9\u7bc7\u6587\u7ae0\u540c\u65f6\u8fd8\u8ba8\u8bba\u4e86Java8\u5bf9GC\u7b97\u6cd5\u7684\u5f71\u54cd\u53ca\u5176\u4ed6\u7ec6\u8282\u4e0a\u7684\u6539\u53d8.\u8ba9\u6211\u4eec\u518d\u56de\u5230GC\u7b97\u6cd5\u4e0a,\u6839\u636eUnderstanding Java Garbage Collection<\/em>\u8fd9\u7bc7\u6587\u7ae0\u6240\u8ff0,\u5e76\u53d1\u6807\u8bb0\u548c\u6e05\u9664GC(\u5373\"CMS\")\u7b97\u6cd5\u624d\u662f\u9002\u5408\u7f51\u7edc\u670d\u52a1\u7aef\u5e94\u7528\u7684\u6700\u4f73\u7b97\u6cd5.\u5e76\u884cGC\u7b97\u6cd5\u9002\u5408\u90a3\u4e9b\u5185\u90e8\u53ef\u9884\u6d4b\u7684\u5e94\u7528\u3002<\/p>\n G1\u548cCMS\u662f\u5e76\u53d1\u64cd\u4f5c\u7684\u7406\u60f3\u9009\u62e9,\u4f46\u4ecd\u7136\u4f1a\u5f15\u8d77(\u5e94\u7528)\u9891\u7e41\u505c\u987f.\u5b9e\u9645\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u4f60\u5982\u4f55\u53d6\u820d.\u4e3e\u4f8b\u6765\u8bf4,\u5c3d\u7ba1\u9009\u62e9\u5e76\u884c\u7b97\u6cd5\u4f1a\u5e26\u6765\u66f4\u957f\u7684GC\u505c\u987f\u65f6\u95f4,\u4f46\u76f8\u8f83\u4e8e\u5176\u4ed6GC\u7b97\u6cd5,\u9009\u62e9\u5e76\u884c\u7b97\u6cd5\u4ecd\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\u3002<\/p>\n Java\u5185\u5b58\u5806\u5728\u8fce\u5408\u5185\u5b58\u9700\u6c42\u65b9\u9762\u62c5\u4efb\u4e86\u81f3\u5173\u91cd\u8981\u89d2\u8272.\u901a\u5e38\u66f4\u597d\u7684\u505a\u6cd5\u662f\u521d\u59cb\u65f6\u5206\u914d\u6700\u5c0f\u7684\u5806,\u7136\u540e\u901a\u8fc7\u6301\u7eed\u7684\u6d4b\u8bd5\u4e0d\u65ad\u589e\u52a0\u5b83\u7684\u5927\u5c0f.\u5927\u591a\u6570\u65f6\u5019\u4f18\u5316\u95ee\u9898\u90fd\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u5806\u7684\u5927\u5c0f\u89e3\u51b3,\u4f46\u5982\u679c\u5b58\u5728\u5927\u91cf\u7684GC\u5f00\u9500,\u5219\u8be5\u89e3\u51b3\u65b9\u6848\u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n GC\u5f00\u9500\u8fd8\u4f1a\u4f7f\u541e\u5410\u91cf\u6025\u5267\u4e0b\u964d,\u8fdb\u800c\u4f7f\u5f97\u5e94\u7528\u96be\u4ee5\u5f62\u5bb9\u7684\u6162.\u6b64\u5916,\u53ca\u65e9\u8c03\u6574GC\u53ef\u4ee5\u5e2e\u52a9\u4f60\u907f\u514d\u5806\u5927\u5c0f\u5206\u914d\u7684\u95ee\u9898.\u5f00\u59cb\u7684\u65f6\u5019,\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u4f551GB\u52308GB\u7684\u5806\u5927\u5c0f.\u5f53\u4f60\u9009\u62e9\u6b63\u786e\u7684\u5806\u5927\u5c0f,\u8001\u751f\u4ee3\u548c\u65b0\u751f\u4ee3\u5bf9\u8c61\u7684\u6982\u5ff5\u4e5f\u5c31\u4e0d\u9700\u8981\u4e86.\u603b\u800c\u8a00\u4e4b,\u5806\u5927\u5c0f\u5e94\u8be5\u53d6\u51b3\u4e8e\u8001\u751f\u4ee3\u548c\u65b0\u751f\u4ee3\u5bf9\u8c61\u7684\u6bd4\u7387,\u4e4b\u524d\u7684GC\u4f18\u5316\u548c\u5bf9\u8c61\u96c6\u5408(\u5373\u6240\u6709\u5bf9\u8c61\u5360\u7528\u7684\u5185\u5b58\u5927\u5c0f)\u3002 \u5173\u952e\u4ee3\u7801\u4f18\u5316\u662f\u4f18\u5316\u4f60\u7684Java\u5e94\u7528\u6700\u597d\u7684\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u7684\u5e94\u7528\u5bf9GC\u548c\u5806\u4f18\u5316\u6ca1\u6709\u53cd\u5e94,\u90a3\u4e48\u6700\u597d\u662f\u505a\u67b6\u6784\u6539\u8fdb\u5e76\u5173\u6ce8\u4e8e\u4f60\u7684\u5e94\u7528\u662f\u5982\u4f55\u5904\u7406\u4fe1\u606f\u7684.\u4f7f\u7528\u806a\u660e\u7684\u7b97\u6cd5\u5e76\u7ba1\u7406\u597d\u5bf9\u8c61\u5c31\u80fd\u89e3\u51b3\u5927\u91cf\u7684\u95ee\u9898,\u5305\u62ec\u5185\u5b58\u788e\u7247,\u5806\u5927\u5c0f\u95ee\u9898\u548c\u5783\u573e\u6536\u96c6\u7684\u95ee\u9898\u3002<\/p>\n Java\u63d0\u4f9b\u4e86\u591a\u4e2a\u51fd\u6570\u6765\u63d0\u5347\u7b97\u6cd5\u6548\u7387\uff0c\u5982\u679c\u4f60\u4f7f\u7528StringBuilder\u4ee3\u66ff\u7b80\u5355\u7684String,\u4f60\u53ef\u4ee5\u5f97\u5230\u5fae\u4e4e\u5176\u5fae\u7684\u6027\u80fd\u63d0\u5347\u3002\u4e0d\u8fc7,\u6211\u4eec\u8fd8\u6709\u5176\u4ed6\u65b9\u5f0f\u5728\u4ee3\u7801\u5c42\u9762\u8fdb\u884c\u4f18\u5316\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u4e0b\u9762\u8fd9\u4e9b\u4f18\u5316\u65b9\u6cd5\u3002<\/p>\n \u67e5\u770b\u66f4\u591a\u5173\u4e8e\u4ee3\u7801\u7684\u4f18\u5316Top 10 Easy Performance. Optimisations in Java\u3002<\/em><\/p>\n java\u7684\u6027\u80fd\u4f18\u5316\u53ef\u662f\u4e00\u4e2a\u5927\u8bfe\u9898\uff0c \u85c9\u7740\u8fd9\u7247\u6587\u7ae0\u629b\u7816\u5f15\u7389\u3002\u5982\u679c\u60a8\u8ba4\u4e3a\u6587\u7ae0\u8fd8\u9700\u8981\u6dfb\u52a0\u8865\u5145\uff0c\u522b\u5fd8\u4e86\u5728\u4e0b\u9762\u7684\u8bc4\u8bba\u4e2d\u5206\u4eab\u60a8\u7684\u89c2\u70b9\u3002<\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttps:\/\/coyee.com\/article\/11118-5-great-java-performance-optimization-tricks<\/a><\/p>\n |