{"id":9256,"date":"2023-02-08T19:30:12","date_gmt":"2023-02-08T11:30:12","guid":{"rendered":"http:\/\/123.57.164.21\/?p=9256"},"modified":"2023-02-10T08:53:20","modified_gmt":"2023-02-10T00:53:20","slug":"%e8%bf%9b%e5%87%bb%e7%9a%84-java-%ef%bc%8c%e4%ba%91%e5%8e%9f%e7%94%9f%e6%97%b6%e4%bb%a3%e7%9a%84%e8%9c%95%e5%8f%98","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=9256","title":{"rendered":"\u8fdb\u51fb\u7684 Java \uff0c\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u8715\u53d8"},"content":{"rendered":"\n<p>\u5bfc\u8bfb\uff1a\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u6765\u4e34\uff0c\u4e0eJava \u5f00\u53d1\u8005\u5230\u5e95\u6709\u4ec0\u4e48\u8054\u7cfb\uff1f\u6709\u4eba\u8bf4\uff0c\u4e91\u539f\u751f\u538b\u6839\u4e0d\u662f\u4e3a\u4e86Java\u5b58\u5728\u7684\u3002\u7136\u800c\uff0c\u672c\u6587\u7684\u4f5c\u8005\u5374\u8ba4\u4e3a\u4e91\u539f\u751f\u65f6\u4ee3\uff0cJava \u4f9d\u7136\u53ef\u4ee5\u80dc\u4efb\u201c\u5de8\u4eba\u201d\u7684\u89d2\u8272\u3002\u4f5c\u8005\u5e0c\u671b\u901a\u8fc7\u4e00\u7cfb\u5217\u5b9e\u9a8c\uff0c\u5f00\u62d3\u540c\u5b66\u89c6\u91ce\uff0c\u63d0\u4f9b\u6709\u76ca\u601d\u8003\u3002<\/p>\n\n\n\n<p>\u5728\u4f01\u4e1a\u8f6f\u4ef6\u9886\u57df\uff0cJava \u4f9d\u7136\u662f\u7edd\u5bf9\u738b\u8005\uff0c\u4f46\u5b83\u8ba9\u5f00\u53d1\u8005\u65e2\u7231\u53c8\u6068\u3002\u4e00\u65b9\u9762\u56e0\u4e3a\u5176\u4e30\u5bcc\u7684\u751f\u6001\u548c\u5b8c\u5584\u7684\u5de5\u5177\u652f\u6301\uff0c\u53ef\u4ee5\u6781\u5927\u63d0\u5347\u4e86\u5e94\u7528\u5f00\u53d1\u6548\u7387\uff1b\u4f46\u5728\u8fd0\u884c\u65f6\u6548\u7387\u65b9\u9762\uff0cJava \u4e5f\u80cc\u8d1f\u7740\u201d\u5185\u5b58\u541e\u566c\u8005\u201c\uff0c\u201cCPU \u6495\u88c2\u8005\u201c\u7684\u6076\u540d\uff0c\u6301\u7eed\u53d7\u5230 NodeJS\u3001Python\u3001Golang \u7b49\u65b0\u8001\u8bed\u8a00\u7684\u6311\u6218\u3002<\/p>\n\n\n\n<p>\u5728\u6280\u672f\u793e\u533a\uff0c\u6211\u4eec\u7ecf\u5e38\u770b\u5230\u6709\u4eba\u5728\u5531\u8870 Java \u6280\u672f\uff0c\u8ba4\u4e3a\u5176\u4e0d\u518d\u7b26\u5408\u4e91\u539f\u751f\u8ba1\u7b97\u53d1\u5c55\u7684\u8d8b\u52bf\u3002\u6211\u4eec\u5148\u629b\u5f00\u8fd9\u4e9b\u89c2\u70b9\uff0c\u9996\u5148\u601d\u8003\u4e00\u4e0b\u4e91\u539f\u751f\u5bf9\u5e94\u7528\u8fd0\u884c\u65f6\u7684\u4e0d\u540c\u9700\u6c42\u3002<\/p>\n\n\n\n<ul><li>\u4f53\u79ef\u66f4\u5c0f &#8211; \u5bf9\u4e8e\u5fae\u670d\u52a1\u5206\u5e03\u5f0f\u67b6\u6784\u800c\u8a00\uff0c\u66f4\u5c0f\u7684\u4f53\u79ef\u610f\u5473\u7740\u66f4\u5c11\u7684\u4e0b\u8f7d\u5e26\u5bbd\uff0c\u66f4\u5feb\u7684\u5206\u53d1\u4e0b\u8f7d\u901f\u5ea6\u3002<\/li><\/ul>\n\n\n\n<ul><li>\u542f\u52a8\u901f\u5ea6\u66f4\u5feb &#8211; \u5bf9\u4e8e\u4f20\u7edf\u5355\u4f53\u5e94\u7528\uff0c\u542f\u52a8\u901f\u5ea6\u4e0e\u8fd0\u884c\u6548\u7387\u76f8\u6bd4\u4e0d\u662f\u4e00\u4e2a\u5173\u952e\u7684\u6307\u6807\u3002\u539f\u56e0\u662f\uff0c\u8fd9\u4e9b\u5e94\u7528\u91cd\u542f\u548c\u53d1\u5e03\u9891\u7387\u76f8\u5bf9\u8f83\u4f4e\u3002\u7136\u800c\u5bf9\u4e8e\u9700\u8981\u5feb\u901f\u8fed\u4ee3\u3001\u6c34\u5e73\u6269\u5c55\u7684\u5fae\u670d\u52a1\u5e94\u7528\u800c\u8a00\uff0c\u66f4\u5feb\u7684\u7684\u542f\u52a8\u901f\u5ea6\u5c31\u610f\u5473\u7740\u66f4\u9ad8\u7684\u4ea4\u4ed8\u6548\u7387\uff0c\u548c\u66f4\u52a0\u5feb\u901f\u7684\u56de\u6eda\u3002\u5c24\u5176\u5f53\u4f60\u9700\u8981\u53d1\u5e03\u4e00\u4e2a\u6709\u6570\u767e\u4e2a\u526f\u672c\u7684\u5e94\u7528\u65f6\uff0c\u7f13\u6162\u7684\u542f\u52a8\u901f\u5ea6\u5c31\u662f\u65f6\u95f4\u6740\u624b\u3002\u5bf9\u4e8eServerless \u5e94\u7528\u800c\u8a00\uff0c\u7aef\u5230\u7aef\u7684\u51b7\u542f\u52a8\u901f\u5ea6\u5219\u66f4\u4e3a\u5173\u952e\uff0c\u5373\u4f7f\u5e95\u5c42\u5bb9\u5668\u6280\u672f\u53ef\u4ee5\u5b9e\u73b0\u767e\u6beb\u79d2\u8d44\u6e90\u5c31\u7eea\uff0c\u5982\u679c\u5e94\u7528\u65e0\u6cd5\u5728500ms\u5185\u5b8c\u6210\u542f\u52a8\uff0c\u7528\u6237\u5c31\u4f1a\u611f\u77e5\u5230\u8bbf\u95ee\u5ef6\u8fdf\u3002<\/li><\/ul>\n\n\n\n<ul><li>\u5360\u7528\u8d44\u6e90\u66f4\u5c11 &#8211; \u8fd0\u884c\u65f6\u66f4\u4f4e\u7684\u8d44\u6e90\u5360\u7528\uff0c\u610f\u5473\u7740\u66f4\u9ad8\u7684\u90e8\u7f72\u5bc6\u5ea6\u548c\u66f4\u4f4e\u7684\u8ba1\u7b97\u6210\u672c\u3002\u540c\u65f6\uff0c\u5728JVM\u542f\u52a8\u65f6\u9700\u8981\u6d88\u8017\u5927\u91cfCPU\u8d44\u6e90\u5bf9\u5b57\u8282\u7801\u8fdb\u884c\u7f16\u8bd1\uff0c\u964d\u4f4e\u542f\u52a8\u65f6\u8d44\u6e90\u6d88\u8017\uff0c\u53ef\u4ee5\u51cf\u5c11\u8d44\u6e90\u4e89\u62a2\uff0c\u66f4\u597d\u4fdd\u969c\u5176\u4ed6\u5e94\u7528SLA\u3002<\/li><\/ul>\n\n\n\n<ul><li>\u652f\u6301\u6c34\u5e73\u6269\u5c55 &#8211; JVM\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u5f0f\u5bfc\u81f4\u5176\u5bf9\u5927\u5185\u5b58\u7ba1\u7406\u7684\u76f8\u5bf9\u4f4e\u6548\uff0c\u4e00\u822c\u5e94\u7528\u65e0\u6cd5\u901a\u8fc7\u914d\u7f6e\u66f4\u5927\u7684heap size\u5b9e\u73b0\u6027\u80fd\u63d0\u5347\uff0c\u5f88\u5c11\u6709Java\u5e94\u7528\u80fd\u591f\u6709\u6548\u4f7f\u752816G\u5185\u5b58\u6216\u8005\u66f4\u9ad8\u3002\u53e6\u4e00\u65b9\u9762\uff0c\u968f\u7740\u5185\u5b58\u6210\u672c\u7684\u4e0b\u964d\u548c\u865a\u62df\u5316\u7684\u6d41\u884c\uff0c\u5927\u5185\u5b58\u914d\u6bd4\u5df2\u7ecf\u6210\u4e3a\u8d8b\u52bf\u3002\u6240\u4ee5\u6211\u4eec\u4e00\u822c\u662f\u91c7\u7528\u6c34\u5e73\u6269\u5c55\u7684\u65b9\u5f0f\uff0c\u540c\u65f6\u90e8\u7f72\u591a\u4e2a\u5e94\u7528\u526f\u672c\uff0c\u5728\u4e00\u4e2a\u8ba1\u7b97\u8282\u70b9\u4e2d\u53ef\u80fd\u8fd0\u884c\u4e00\u4e2a\u5e94\u7528\u7684\u591a\u4e2a\u526f\u672c\u6765\u63d0\u5347\u8d44\u6e90\u5229\u7528\u7387\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u70ed\u8eab\u51c6\u5907<\/strong><\/p>\n\n\n\n<p>\u719f\u6089Spring\u6846\u67b6\u7684\u5f00\u53d1\u8005\u5927\u591a\u5bf9 Spring Petclinic \u4e0d\u4f1a\u964c\u751f\u3002\u672c\u6587\u5c06\u501f\u52a9\u8fd9\u4e2a\u8457\u540d\u793a\u4f8b\u5e94\u7528\u6765\u6f14\u793a\u5982\u4f55\u8ba9\u6211\u4eec\u7684Java\u5e94\u7528\u53d8\u5f97\u66f4\u5c0f\uff0c\u66f4\u5feb\uff0c\u66f4\u8f7b\uff0c\u66f4\u5f3a\u5927\uff01<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1024x600.png\" alt=\"\" class=\"wp-image-9258\" width=\"595\" height=\"349\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1024x600.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-300x176.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-768x450.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-830x486.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-230x135.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-350x205.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-480x281.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247.png 1424w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eecfork\u4e86IBM\u7684Michael Thompson\u7684\u793a\u4f8b\uff0c\u5e76\u505a\u4e86\u4e00\u4e9b\u8c03\u6574\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git clone https:\/\/github.com\/denverdino\/adopt-openj9-spring-boot\n$ cd adopt-openj9-spring-boot<\/pre>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u4f1a\u4e3aPetClinic\u5e94\u7528\u6784\u5efa\u4e00\u4e2aDocker\u955c\u50cf\u3002\u5728Dockerfile\u4e2d\uff0c\u6211\u4eec\u5229\u7528OpenJDK\u4f5c\u4e3a\u57fa\u7840\u955c\u50cf\uff0c\u5b89\u88c5Maven\uff0c\u4e0b\u8f7d\u3001\u7f16\u8bd1\u3001\u6253\u5305Spring PetClinic\u5e94\u7528\uff0c\u6700\u540e\u8bbe\u7f6e\u955c\u50cf\u7684\u542f\u52a8\u53c2\u6570\u5b8c\u6210\u955c\u50cf\u6784\u5efa\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ cat Dockerfile.openjdk\nFROM adoptopenjdk\/openjdk8\nRUN sed -i 's\/archive.ubuntu.com\/mirrors.aliyun.com\/' \/etc\/apt\/sources.list\nRUN apt-get update\nRUN apt-get install -y \\\n    git \\\n    maven\nWORKDIR \/tmp\nRUN git clone https:\/\/github.com\/spring-projects\/spring-petclinic.git\nWORKDIR \/tmp\/spring-petclinic\nRUN mvn install\nWORKDIR \/tmp\/spring-petclinic\/target\nCMD [\"java\",\"-jar\",\"spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar\"]<\/pre>\n\n\n\n<p><strong>\u6784\u5efa\u955c\u50cf\u5e76\u6267\u884c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker build -t petclinic-openjdk-hotspot -f Dockerfile.openjdk .\n$ docker run --name hotspot -p 8080:8080 --rm petclinic-openjdk-hotspot\n              |\\      _,,,--,,_\n             \/,`.-'`'   ._  \\-;;,_\n  _______ __|,4-  ) )_   .;.(__`'-'__     ___ __    _ ___ _______\n |       | '---''(_\/._)-'(_\\_)   |   |   |   |  |  | |   |       |\n |    _  |    ___|_     _|       |   |   |   |   |_| |   |       | __ _ _\n |   |_| |   |___  |   | |       |   |   |   |       |   |       | \\ \\ \\ \\\n |    ___|    ___| |   | |      _|   |___|   |  _    |   |      _|  \\ \\ \\ \\\n |   |   |   |___  |   | |     |_|       |   | | |   |   |     |_    ) ) ) )\n |___|   |_______| |___| |_______|_______|___|_|  |__|___|_______|  \/ \/ \/ \/\n ==================================================================\/_\/_\/_\/\n...\n2019-09-11 01:58:23.156  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''\n2019-09-11 01:58:23.158  INFO 1 --- [           main] o.s.s.petclinic.PetClinicApplication     : Started PetClinicApplication in 7.458 seconds (JVM running for 8.187)<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7 <a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/localhost\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/localhost<\/a>:8080\/ \u8bbf\u95ee\u5e94\u7528\u754c\u9762\u3002<br>\u68c0\u67e5\u4e00\u4e0b\u6784\u5efa\u51fa\u7684Docker\u955c\u50cf\uff0c \u201dpetclinic-openjdk-openj9\u201c \u7684\u5927\u5c0f\u4e3a871MB\uff0c\u800c\u57fa\u7840\u955c\u50cf \u201dadoptopenjdk\/openjdk8\u201c \u4ec5\u6709 300MB\uff01\u8fd9\u8d27\u4e5f\u592a\u81a8\u80c0\u4e86!<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker images petclinic-openjdk-hotspot\nREPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE\npetclinic-openjdk-hotspot   latest              469f73967d03        26 hours ago        871MB<\/pre>\n\n\n\n<p>\u539f\u56e0\u662f\uff1a\u4e3a\u4e86\u6784\u5efaSpring\u5e94\u7528\uff0c\u6211\u4eec\u5728\u955c\u50cf\u4e2d\u5f15\u5165\u4e86\u4e00\u7cfb\u5217\u7f16\u8bd1\u65f6\u4f9d\u8d56\uff0c\u5982 Git\uff0cMaven\u7b49\uff0c\u5e76\u4ea7\u751f\u4e86\u5927\u91cf\u4e34\u65f6\u7684\u6587\u4ef6\u3002\u7136\u800c\u8fd9\u4e9b\u5185\u5bb9\u5728\u8fd0\u884c\u65f6\u662f\u4e0d\u9700\u8981\u7684\u3002<br>\u5728\u8457\u540d\u7684\u8f6f\u4ef612\u8981\u7d20 \u7b2c\u4e94\u6761\u660e\u786e\u6307\u51fa\u4e86\uff0c\u201dStrictly separate build and run stages.\u201c \u4e25\u683c\u5206\u79bb\u6784\u5efa\u548c\u8fd0\u884c\u9636\u6bb5\uff0c\u4e0d\u4f46\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u63d0\u5347\u5e94\u7528\u7684\u53ef\u8ffd\u6eaf\u6027\uff0c\u4fdd\u969c\u5e94\u7528\u4ea4\u4ed8\u7684\u4e00\u81f4\u6027\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u51cf\u5c11\u5e94\u7528\u5206\u53d1\u7684\u4f53\u79ef\uff0c\u51cf\u5c11\u5b89\u5168\u98ce\u9669\u3002<\/p>\n\n\n\n<p><strong>\u955c\u50cf\u7626\u8eab<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Docker\u63d0\u4f9b\u4e86Multi-stage Build\uff08\u591a\u9636\u6bb5\u6784\u5efa\uff09\uff0c\u53ef\u4ee5\u5b9e\u73b0\u955c\u50cf\u7626\u8eab\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-1024x558.png\" alt=\"\" class=\"wp-image-9260\" width=\"551\" height=\"299\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-1024x558.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-300x163.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-768x418.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-830x452.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-230x125.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1-480x261.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-1.png 1388w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/figure><\/div>\n\n\n\n<p>\u6211\u4eec\u5c06\u955c\u50cf\u6784\u5efa\u5206\u6210\u4e24\u4e2a\u9636\u6bb5\uff1a<\/p>\n\n\n\n<p>\u5728 \u201dbuild\u201c \u9636\u6bb5\u4f9d\u7136\u91c7\u7528JDK\u4f5c\u4e3a\u57fa\u7840\u955c\u50cf\uff0c\u5e76\u5229\u7528Maven\u8fdb\u884c\u5e94\u7528\u6784\u5efa\uff1b<br>\u5728\u6700\u7ec8\u53d1\u5e03\u7684\u955c\u50cf\u4e2d\uff0c\u6211\u4eec\u4f1a\u91c7\u7528JRE\u7248\u672c\u4f5c\u4e3a\u57fa\u7840\u955c\u50cf\uff0c\u5e76\u4ece\u201dbuild\u201c \u955c\u50cf\u4e2d\u76f4\u63a5\u62f7\u8d1d\u51fa\u751f\u6210\u7684jar\u6587\u4ef6\u3002\u8fd9\u610f\u5473\u7740\u5728\u6700\u7ec8\u53d1\u5e03\u7684\u955c\u50cf\u4e2d\uff0c\u53ea\u5305\u542b\u8fd0\u884c\u65f6\u6240\u9700\u5fc5\u8981\u5185\u5bb9\uff0c\u4e0d\u5305\u542b\u4efb\u4f55\u7f16\u8bd1\u65f6\u4f9d\u8d56\uff0c\u5927\u5927\u51cf\u5c11\u4e86\u955c\u50cf\u4f53\u79ef\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ cat Dockerfile.openjdk-slim\nFROM adoptopenjdk\/openjdk8 AS build\nRUN sed -i 's\/archive.ubuntu.com\/mirrors.aliyun.com\/' \/etc\/apt\/sources.list\nRUN apt-get update\nRUN apt-get install -y \\\n    git \\\n    maven\nWORKDIR \/tmp\nRUN git clone https:\/\/github.com\/spring-projects\/spring-petclinic.git\nWORKDIR \/tmp\/spring-petclinic\nRUN mvn install\nFROM adoptopenjdk\/openjdk8:jre8u222-b10-alpine-jre\nCOPY --from=build \/tmp\/spring-petclinic\/target\/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar\nCMD [\"java\",\"-jar\",\"spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar\"]\n\n<\/pre>\n\n\n\n<p><strong>\u67e5\u770b\u4e00\u4e0b\u65b0\u955c\u50cf\u5927\u5c0f\uff0c\u4ece 871MB \u51cf\u5c11\u5230 167MB\uff01<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker build -t petclinic-openjdk-hotspot-slim -f Dockerfile.openjdk-slim .\n...\n$ docker images petclinic-openjdk-hotspot-slim\nREPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE\npetclinic-openjdk-hotspot-slim   latest              d1f1ca316ec0        26 hours ago        167MB\n<\/pre>\n\n\n\n<p>\u955c\u50cf\u7626\u8eab\u4e4b\u540e\u5c06\u5927\u5927\u52a0\u901f\u5e94\u7528\u5206\u53d1\u901f\u5ea6\uff0c\u6211\u4eec\u662f\u5426\u6709\u529e\u6cd5\u4f18\u5316\u5e94\u7528\u7684\u542f\u52a8\u901f\u5ea6\u5462\uff1f<\/p>\n\n\n\n<p><strong>\u4ece JIT \u5230 AOT &#8211; \u542f\u52a8\u63d0\u901f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3Java\u542f\u52a8\u7684\u6027\u80fd\u74f6\u9888\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u7406\u89e3JVM\u7684\u5b9e\u73b0\u539f\u7406\u3002\u4e3a\u4e86\u5b9e\u73b0\u201c\u4e00\u6b21\u7f16\u5199\uff0c\u968f\u5904\u8fd0\u884c\u201d\u7684\u80fd\u529b\uff0cJava\u7a0b\u5e8f\u4f1a\u88ab\u7f16\u8bd1\u6210\u5b9e\u73b0\u67b6\u6784\u65e0\u5173\u7684\u5b57\u8282\u7801\u3002JVM\u5728\u8fd0\u884c\u65f6\u5c06\u5b57\u8282\u7801\u8f6c\u6362\u6210\u672c\u5730\u673a\u5668\u7801\u6267\u884c\u3002\u8fd9\u4e2a\u8f6c\u6362\u8fc7\u7a0b\u51b3\u5b9a\u4e86Java\u5e94\u7528\u7684\u542f\u52a8\u548c\u8fd0\u884c\u901f\u5ea6\u3002\u4e3a\u4e86\u63d0\u5347\u6267\u884c\u6548\u7387\uff0cJVM\u5f15\u5165\u4e86JIT compiler\uff08Just in Time Compiler\uff0c\u5373\u65f6\u7f16\u8bd1\u5668\uff09\uff0c\u5176\u4e2dSun\/Oracle\u516c\u53f8\u7684HotSpot\u662f\u6700\u8457\u540dJIT\u7f16\u8bd1\u5668\u5b9e\u73b0\u3002\u5b83\u63d0\u4f9b\u4e86\u81ea\u9002\u5e94\u4f18\u5316\u5668\uff0c\u53ef\u4ee5\u52a8\u6001\u5206\u6790\u3001\u53d1\u73b0\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u5173\u952e\u8def\u5f84\uff0c\u5e76\u8fdb\u884c\u7f16\u8bd1\u4f18\u5316\u3002HotSpot\u7684\u51fa\u73b0\u6781\u5927\u63d0\u5347\u4e86Java\u5e94\u7528\u7684\u6267\u884c\u6548\u7387\uff0c\u5728Java 1.4\u4ee5\u540e\u6210\u4e3a\u4e86\u7f3a\u7701\u7684VM\u5b9e\u73b0\u3002\u4f46\u662fHotSpot VM\u5728\u542f\u52a8\u65f6\u624d\u5bf9\u5b57\u8282\u7801\u8fdb\u884c\u7f16\u8bd1\uff0c\u4e00\u65b9\u9762\u5bfc\u81f4\u542f\u52a8\u65f6\u6267\u884c\u6548\u7387\u4e0d\u9ad8\uff0c\u4e00\u65b9\u9762\u7f16\u8bd1\u548c\u4f18\u5316\u9700\u8981\u5f88\u591a\u7684CPU\u8d44\u6e90\uff0c\u62d6\u6162\u4e86\u542f\u52a8\u901f\u5ea6\u3002\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u4f18\u5316\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u63d0\u5347\u542f\u52a8\u901f\u5ea6\u5462\uff1f<br>\u719f\u6089Java\u6c5f\u6e56\u5386\u53f2\u7684\u540c\u5b66\u5e94\u8be5\u4f1a\u77e5\u9053IBM J9 VM\uff0c\u5b83\u662f\u7528\u4e8eIBM\u4f01\u4e1a\u7ea7\u8f6f\u4ef6\u4ea7\u54c1\u7684\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684JVM\uff0c\u5e2e\u52a9IBM\u5960\u5b9a\u4e86\u5546\u4e1a\u5e94\u7528\u5e73\u53f0\u4e2d\u95f4\u4ef6\u7684\u9738\u4e3b\u5730\u4f4d\u30022017\u5e749\u6708\uff0cIBM \u5c06 J9 \u6350\u732e\u7ed9 Eclipse \u57fa\u91d1\u4f1a\uff0c\u5e76\u66f4\u540d Eclipse OpenJ9\uff0c\u5f00\u542f\u5f00\u6e90\u4e4b\u65c5\u3002<br>OpenJ9 \u63d0\u4f9b\u4e86Shared Class Cache (SCC \u5171\u4eab\u7c7b\u7f13\u5b58) \u548c Ahead-of-Time (AOT \u63d0\u524d\u7f16\u8bd1) \u6280\u672f\uff0c\u663e\u8457\u51cf\u5c11\u4e86Java\u5e94\u7528\u542f\u52a8\u65f6\u95f4\u3002<br>SCC \u662f\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff0c\u5305\u542b\u4e86J9 VM\u5bf9\u5b57\u8282\u7801\u7684\u6267\u884c\u5206\u6790\u4fe1\u606f\u548c\u5df2\u7ecf\u7f16\u8bd1\u751f\u6210\u7684\u672c\u5730\u4ee3\u7801\u3002\u5f00\u542f AOT \u7f16\u8bd1\u540e\uff0c\u4f1a\u5c06JVM\u7f16\u8bd1\u7ed3\u679c\u4fdd\u5b58\u5728 SCC \u4e2d\uff0c\u5728\u540e\u7eed JVM \u542f\u52a8\u4e2d\u53ef\u4ee5\u76f4\u63a5\u91cd\u7528\u3002\u4e0e\u542f\u52a8\u65f6\u8fdb\u884c\u7684 JIT \u7f16\u8bd1\u76f8\u6bd4\uff0c\u4ece SCC \u52a0\u8f7d\u9884\u7f16\u8bd1\u7684\u5b9e\u73b0\u8981\u5feb\u5f97\u591a\uff0c\u800c\u4e14\u6d88\u8017\u7684\u8d44\u6e90\u8981\u66f4\u5c11\u3002\u542f\u52a8\u65f6\u95f4\u53ef\u4ee5\u5f97\u5230\u660e\u663e\u6539\u5584\u3002<br>\u6211\u4eec\u5f00\u59cb\u6784\u5efa\u4e00\u4e2a\u5305\u542bAOT\u4f18\u5316\u7684Docker\u5e94\u7528\u955c\u50cf<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$cat Dockerfile.openj9.warmed\nFROM adoptopenjdk\/openjdk8-openj9 AS build\nRUN sed -i 's\/archive.ubuntu.com\/mirrors.aliyun.com\/' \/etc\/apt\/sources.list\nRUN apt-get update\nRUN apt-get install -y \\\n    git \\\n    maven\nWORKDIR \/tmp\nRUN git clone https:\/\/github.com\/spring-projects\/spring-petclinic.git\nWORKDIR \/tmp\/spring-petclinic\nRUN mvn install\nFROM adoptopenjdk\/openjdk8-openj9:jre8u222-b10_openj9-0.15.1-alpine\nCOPY --from=build \/tmp\/spring-petclinic\/target\/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar\n# Start and stop the JVM to pre-warm the class cache\nRUN \/bin\/sh -c 'java -Xscmx50M -Xshareclasses -Xquickstart -jar spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar &amp;' ; sleep 20 ; ps aux | grep java | grep petclinic | awk '{print $1}' | xargs kill -1\nCMD [\"java\",\"-Xscmx50M\",\"-Xshareclasses\",\"-Xquickstart\", \"-jar\",\"spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar\"]<\/pre>\n\n\n\n<p>\u5176\u4e2d Java \u53c2\u6570 -Xshareclasses \u5f00\u542fSCC\uff0c-Xquickstart \u5f00\u542fAOT\u3002<br>\u5728Dockerfile\u4e2d\uff0c\u6211\u4eec\u8fd0\u7528\u4e86\u4e00\u4e2a\u6280\u5de7\u6765\u9884\u70edSCC\u3002\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u542f\u52a8JVM\u52a0\u8f7d\u5e94\u7528\uff0c\u5e76\u5f00\u542fSCC\u548cAOT\uff0c\u5728\u5e94\u7528\u542f\u52a8\u540e\u505c\u6b62JVM\u3002\u8fd9\u6837\u5c31\u5728Docker\u955c\u50cf\u4e2d\u5305\u542b\u4e86\u751f\u6210\u7684SCC\u6587\u4ef6\u3002<br>\u7136\u540e\uff0c\u6211\u4eec\u6765\u6784\u5efaDocker\u955c\u50cf\u5e76\u542f\u52a8\u6d4b\u8bd5\u5e94\u7528\uff0c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker build -t petclinic-openjdk-openj9-warmed-slim -f Dockerfile.openj9.warmed-slim .\n$ docker run --name hotspot -p 8080:8080 --rm petclinic-openjdk-openj9-warmed-slim\n...\n2019-09-11 03:35:20.192  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''\n2019-09-11 03:35:20.193  INFO 1 --- [           main] o.s.s.petclinic.PetClinicApplication     : Started PetClinicApplication in 3.691 seconds (JVM running for 3.952)\n<\/pre>\n\n\n\n<p>\u2026<br>\u53ef\u4ee5\u770b\u5230\uff0c\u542f\u52a8\u65f6\u95f4\u5df2\u7ecf\u4ece\u4e4b\u524d\u7684 8.2s \u51cf\u5c11\u5230 4s\uff0c\u63d0\u5347\u8fd150%\u3002<br>\u5728\u8fd9\u4e2a\u65b9\u6848\u4e2d\uff0c\u6211\u4eec\u4e00\u65b9\u9762\u5c06\u8017\u65f6\u8017\u80fd\u7684\u7f16\u8bd1\u4f18\u5316\u8fc7\u7a0b\u8f6c\u79fb\u5230\u6784\u5efa\u65f6\u5b8c\u6210\uff0c\u4e00\u65b9\u9762\u91c7\u7528\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u7684\u65b9\u6cd5\uff0c\u5c06\u9884\u7f16\u8bd1\u7684SCC\u7f13\u5b58\u4fdd\u5b58\u5230Docker\u955c\u50cf\u4e2d\u3002\u5728\u5bb9\u5668\u542f\u52a8\u65f6\uff0cJVM\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u6765\u52a0\u8f7dSCC\uff0c\u4f18\u5316\u4e86\u542f\u52a8\u901f\u5ea6\u548c\u8d44\u6e90\u5360\u7528\u3002<br>\u8fd9\u4e2a\u65b9\u6cd5\u53e6\u5916\u4e00\u4e2a\u4f18\u52bf\u662f\uff1a\u7531\u4e8eDocker\u955c\u50cf\u91c7\u7528\u5206\u5c42\u5b58\u50a8\uff0c\u540c\u4e00\u4e2a\u5bbf\u4e3b\u673a\u4e0a\u7684\u591a\u4e2aDocker\u5e94\u7528\u5b9e\u4f8b\u4f1a\u5171\u4eab\u540c\u4e00\u4efdSCC\u5185\u5b58\u6620\u5c04\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u5728\u5355\u673a\u9ad8\u5bc6\u5ea6\u90e8\u7f72\u65f6\u7684\u5185\u5b58\u6d88\u8017\u3002<br>\u4e0b\u9762\u6211\u4eec\u505a\u4e00\u4e0b\u8d44\u6e90\u6d88\u8017\u7684\u6bd4\u8f83\uff0c\u6211\u4eec\u9996\u5148\u5229\u7528\u57fa\u4e8eHotSpot VM\u7684\u955c\u50cf\uff0c\u540c\u65f6\u542f\u52a84\u4e2aDocker\u5e94\u7528\u5b9e\u4f8b\uff0c30s\u540e\u5229\u7528docker stats\u67e5\u770b\u8d44\u6e90\u6d88\u8017<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ .\/run-hotspot-4.sh\n...\nWait a while ...\nCONTAINER ID        NAME                CPU %               MEM USAGE \/ LIMIT     MEM %               NET I\/O             BLOCK I\/O           PIDS\n0fa58df1a291        instance4           0.15%               597.1MiB \/ 5.811GiB   10.03%              726B \/ 0B           0B \/ 0B             33\n48f021d728bb        instance3           0.13%               648.6MiB \/ 5.811GiB   10.90%              726B \/ 0B           0B \/ 0B             33\na3abb10078ef        instance2           0.26%               549MiB \/ 5.811GiB     9.23%               726B \/ 0B           0B \/ 0B             33\n6a65cb1e0fe5        instance1           0.15%               641.6MiB \/ 5.811GiB   10.78%              906B \/ 0B           0B \/ 0B             33\n\n<\/pre>\n\n\n\n<p>\u2026<br>\u7136\u540e\u4f7f\u7528\u57fa\u4e8eOpenJ9 VM\u7684\u955c\u50cf\uff0c\u540c\u65f6\u542f\u52a84\u4e2aDocker\u5e94\u7528\u5b9e\u4f8b\uff0c\u5e76\u67e5\u770b\u8d44\u6e90\u6d88\u8017<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ .\/run-openj9-warmed-4.sh\n...\nWait a while ...\nCONTAINER ID        NAME                CPU %               MEM USAGE \/ LIMIT     MEM %               NET I\/O             BLOCK I\/O           PIDS\n3a0ba6103425        instance4           0.09%               119.5MiB \/ 5.811GiB   2.01%               1.19kB \/ 0B         0B \/ 446MB          39\nc07ca769c3e7        instance3           0.19%               119.7MiB \/ 5.811GiB   2.01%               1.19kB \/ 0B         16.4kB \/ 120MB      39\n0c19b0cf9fc2        instance2           0.15%               112.1MiB \/ 5.811GiB   1.88%               1.2kB \/ 0B          22.8MB \/ 23.8MB     39\n95a9c4dec3d6        instance1           0.15%               108.6MiB \/ 5.811GiB   1.83%               1.45kB \/ 0B         102MB \/ 414MB       39\n...\n\n<\/pre>\n\n\n\n<p>\u4e0eHotSpot VM\u76f8\u6bd4\uff0cOpenJ9\u7684\u573a\u666f\u4e0b\u5e94\u7528\u5185\u5b58\u5360\u7528\u4ece\u5e73\u5747 600MB \u4e0b\u964d\u5230 120MB\u3002\u60ca\u559c\u4e0d\u60ca\u559c\uff1f<br>\u901a\u5e38\u800c\u8a00\uff0cHotSpot JIT\u6bd4AOT\u53ef\u4ee5\u8fdb\u884c\u66f4\u52a0\u5168\u9762\u548c\u6df1\u5165\u7684\u6267\u884c\u8def\u5f84\u4f18\u5316\uff0c\u4ece\u800c\u6709\u66f4\u9ad8\u7684\u8fd0\u884c\u6548\u7387\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u77db\u76fe\uff0cOpenJ9 \u7684AOT SCC\u53ea\u5728\u542f\u52a8\u9636\u6bb5\u751f\u6548\uff0c\u5728\u540e\u7eed\u8fd0\u884c\u4e2d\u4f1a\u7ee7\u7eed\u5229\u7528JIT\u8fdb\u884c\u5206\u652f\u9884\u6d4b\u3001\u4ee3\u7801\u5185\u8054\u7b49\u6df1\u5ea6\u7f16\u8bd1\u4f18\u5316\u3002<\/p>\n\n\n\n<p>HotSpot\u5728Class Data Sharing (CDS)\u548cAOT\u65b9\u9762\u4e5f\u6709\u4e86\u5f88\u5927\u8fdb\u5c55\uff0c\u4f46\u662fIBM J9\u5728\u8fd9\u65b9\u9762\u66f4\u52a0\u6210\u719f\u3002\u671f\u5f85\u963f\u91cc\u7684Dragonwell\u4e5f\u63d0\u4f9b\u76f8\u5e94\u7684\u4f18\u5316\u652f\u6301\u3002<br>\u601d\u8003\uff1a\u4e0eC\/C++\uff0cGolang, Rust\u7b49\u9759\u6001\u7f16\u8bd1\u8bed\u8a00\u4e0d\u540c\uff0cJava\u91c7\u7528VM\u65b9\u5f0f\u8fd0\u884c\uff0c\u63d0\u5347\u4e86\u5e94\u7528\u53ef\u79fb\u690d\u6027\u7684\u540c\u65f6\u727a\u7272\u4e86\u90e8\u5206\u6027\u80fd\u3002\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u5c06AOT\u505a\u5230\u6781\u81f4\uff1f\u5b8c\u5168\u79fb\u9664\u5b57\u8282\u7801\u5230\u672c\u5730\u4ee3\u7801\u7684\u7f16\u8bd1\u8fc7\u7a0b\uff1f<\/p>\n\n\n\n<p><strong>\u539f\u751f\u4ee3\u7801\u7f16\u8bd1<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4e3a\u4e86\u5c06Java\u5e94\u7528\u7f16\u8bd1\u6210\u672c\u5730\u53ef\u6267\u884c\u4ee3\u7801\uff0c\u6211\u4eec\u9996\u5148\u8981\u89e3\u51b3JVM\u548c\u5e94\u7528\u6846\u67b6\u5728\u8fd0\u884c\u65f6\u7684\u52a8\u6001\u6027\u6311\u6218\u3002JVM\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u7c7b\u52a0\u8f7d\u673a\u5236\uff0cSpring\u7684\u4f9d\u8d56\u6ce8\u5165(DI\uff0cDependency-injection)\u53ef\u4ee5\u5b9e\u73b0\u8fd0\u884c\u65f6\u52a8\u6001\u7c7b\u52a0\u8f7d\u548c\u7ed1\u5b9a\u3002\u5728Spring\u6846\u67b6\u4e2d\uff0c\u53cd\u5c04\uff0cAnnotation \u8fd0\u884c\u65f6\u5904\u7406\u5668\u7b49\u6280\u672f\u4e5f\u88ab\u5e7f\u6cdb\u5e94\u7528\u3002\u8fd9\u4e9b\u52a8\u6001\u6027\u4e00\u65b9\u9762\u63d0\u5347\u4e86\u5e94\u7528\u67b6\u6784\u7684\u7075\u6d3b\u6027\u548c\u6613\u7528\u6027\uff0c\u53e6\u4e00\u65b9\u9762\u4e5f\u964d\u4f4e\u4e86\u5e94\u7528\u7684\u542f\u52a8\u901f\u5ea6\uff0c\u4f7f\u5f97AOT\u539f\u751f\u7f16\u8bd1\u548c\u4f18\u5316\u53d8\u5f97\u975e\u5e38\u590d\u6742\u3002<br>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u6311\u6218\uff0c\u793e\u533a\u6709\u5f88\u591a\u6709\u8da3\u7684\u63a2\u7d22\uff0cMicronaut \u662f\u5176\u4e2d\u4e00\u4e2a\u4f18\u79c0\u4ee3\u8868\u3002\u4e0eSpring\u6846\u67b6\u5e8f\u4e0d\u540c\uff0cMicronaut\u63d0\u4f9b\u4e86\u7f16\u8bd1\u65f6\u7684\u4f9d\u8d56\u6ce8\u5165\u548cAOP\u5904\u7406\u80fd\u529b\uff0c\u5e76\u6700\u5c0f\u5316\u53cd\u5c04\u548c\u52a8\u6001\u4ee3\u7406\u7684\u4f7f\u7528\u3002Micronaut \u5e94\u7528\u6709\u7740\u66f4\u5feb\u7684\u542f\u52a8\u901f\u5ea6\u548c\u66f4\u4f4e\u7684\u5185\u5b58\u5360\u7528\u3002\u66f4\u52a0\u8ba9\u6211\u4eec\u66f4\u611f\u5174\u8da3\u7684\u662fMicronaut\u652f\u6301\u4e0eGraal VM\u914d\u5408\uff0c\u53ef\u4ee5\u5c06Java\u5e94\u7528\u7f16\u8bd1\u6210\u4e3a\u672c\u5730\u6267\u884c\u4ee3\u7801\u5168\u901f\u8fd0\u884c\u3002\u6ce8\uff1aGraalVM\u662fOracle\u63a8\u51fa\u7684\u4e00\u79cd\u65b0\u578b\u901a\u7528\u865a\u62df\u673a\uff0c\u652f\u6301\u591a\u79cd\u8bed\u8a00\uff0c\u53ef\u4ee5\u5c06Java\u5e94\u7528\u7a0b\u5e8f\u7f16\u8bd1\u4e3a\u672c\u5730\u539f\u751f\u5e94\u7528\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-1024x424.png\" alt=\"\" class=\"wp-image-9262\" width=\"591\" height=\"244\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-1024x424.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-300x124.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-768x318.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-830x343.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-230x95.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-350x145.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2-480x199.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/02\/\u56fe\u7247-2.png 1416w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u4e0b\u9762\u5f00\u59cb\u6211\u4eec\u7684\u63a2\u9669<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u6211\u4eec\u5229\u7528Mitz\u63d0\u4f9b\u7684Micronaut\u7248\u672cPetClinic\u793a\u4f8b\u5de5\u7a0b\u5e76\u505a\u4e86\u4e00\u70b9\u70b9\u8c03\u6574\u3002\uff08\u4f7f\u7528Graal VM 19.2\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git clone https:\/\/github.com\/denverdino\/micronaut-petclinic\n$ cd micronaut-petclinic<\/pre>\n\n\n\n<p><strong>\u5176\u4e2dDocker\u955c\u50cf\u7684\u5185\u5bb9\u5982\u4e0b<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ cat Dockerfile\nFROM maven:3.6.1-jdk-8 as build\nCOPY .\/ \/micronaut-petclinic\/\nWORKDIR \/micronaut-petclinic\nRUN mvn package\nFROM oracle\/graalvm-ce:19.2.0 as graalvm\nRUN gu install native-image\nWORKDIR \/work\nCOPY --from=build \/micronaut-petclinic\/target\/micronaut-petclinic-*.jar .\nRUN native-image --no-server -cp micronaut-petclinic-*.jar\nFROM frolvlad\/alpine-glibc\nEXPOSE 8080\nWORKDIR \/app\nCOPY --from=graalvm \/work\/petclinic .\nCMD [\"\/app\/petclinic\"]<\/pre>\n\n\n\n<p><strong>\u5176\u4e2d<\/strong><\/p>\n\n\n\n<p>\u5728 &#8220;build&#8221; \u9636\u6bb5\uff0c\u5229\u7528Maven\u6784\u5efa Micronaut \u7248\u672c\u7684 PetClinic \u5e94\u7528\uff0c<br>\u5728 &#8220;graalvm&#8221; \u9636\u6bb5\uff0c\u6211\u4eec\u901a\u8fc7 native-image \u5c06PetClinic jar\u6587\u4ef6\u8f6c\u5316\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<br>\u5728\u6700\u7ec8\u9636\u6bb5\uff0c\u5c06\u672c\u5730\u53ef\u6267\u884c\u6587\u4ef6\u52a0\u5165\u4e00\u4e2aAlpine Linux\u57fa\u7840\u955c\u50cf<br>\u6784\u5efa\u5e94\u7528<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker-compose build<\/pre>\n\n\n\n<p><strong>\u542f\u52a8\u6d4b\u8bd5\u6570\u636e\u5e93<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker-compose up db<\/pre>\n\n\n\n<p><strong>\u542f\u52a8\u6d4b\u8bd5\u5e94\u7528<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ docker-compose up app\nmicronaut-petclinic_db_1 is up-to-date\nStarting micronaut-petclinic_app_1 ... done\nAttaching to micronaut-petclinic_app_1\napp_1  | 04:57:47.571 [main] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL95Dialect\napp_1  | 04:57:47.649 [main] INFO  org.hibernate.type.BasicTypeRegistry - HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@5f4e0f0\napp_1  | 04:57:47.653 [main] INFO  o.h.tuple.entity.EntityMetamodel - HHH000157: Lazy property fetching available for: com.example.micronaut.petclinic.owner.Owner\napp_1  | 04:57:47.656 [main] INFO  o.h.e.t.j.p.i.JtaPlatformInitiator - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]\napp_1  | 04:57:47.672 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 159ms. Server Running: http:\/\/1285c42bfcd5:8080\n\u5e94\u7528\u542f\u52a8\u901f\u5ea6\u5982\u95ea\u7535\u822c\u63d0\u5347\u81f3 159ms\uff0c\u4ec5\u6709HotSpot VM\u76841\/50\uff01<\/pre>\n\n\n\n<p><strong>\u603b\u7ed3\u4e0e\u540e\u8bb0<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u4f5c\u4e3a\u8fdb\u51fb\u7684\u5de8\u4eba\uff0cJava\u6280\u672f\u5728\u4e91\u539f\u751f\u65f6\u4ee3\u4e5f\u5728\u4e0d\u505c\u5730\u8fdb\u5316\u3002\u5728JDK 8u191\u548cJDK 10\u4e4b\u540e\uff0cJVM\u589e\u5f3a\u4e86\u5728Docker\u5bb9\u5668\u4e2d\u5bf9\u8d44\u6e90\u7684\u611f\u77e5\u3002\u540c\u65f6\u793e\u533a\u4e5f\u5728\u591a\u4e2a\u4e0d\u540c\u65b9\u5411\u63a2\u7d22Java\u6280\u672f\u6808\u7684\u8fb9\u754c\u3002JVM OpenJ9\u4f5c\u4e3a\u4f20\u7edfVM\u7684\u4e00\u5458\uff0c\u5728\u5bf9\u73b0\u6709Java\u5e94\u7528\u4fdd\u6301\u9ad8\u5ea6\u517c\u5bb9\u7684\u540c\u65f6\uff0c\u5bf9\u542f\u52a8\u901f\u5ea6\u548c\u5185\u5b58\u5360\u7528\u505a\u4e86\u7ec6\u81f4\u7684\u4f18\u5316\uff0c\u6bd4\u8f83\u9002\u4e8e\u4e0e\u73b0\u6709Spring\u7b49\u5fae\u670d\u52a1\u67b6\u6784\u914d\u5408\u4f7f\u7528\u3002\u800cMicronaut\/Graal VM\u5219\u53e6\u8f9f\u8e4a\u5f84\uff0c\u901a\u8fc7\u6539\u53d8\u7f16\u7a0b\u6a21\u578b\u548c\u7f16\u8bd1\u8fc7\u7a0b\uff0c\u5c06\u5e94\u7528\u7684\u52a8\u6001\u6027\u5c3d\u53ef\u80fd\u63d0\u524d\u5230\u7f16\u8bd1\u65f6\u671f\u5904\u7406\uff0c\u6781\u5927\u4f18\u5316\u4e86\u5e94\u7528\u542f\u52a8\u65f6\u95f4\uff0c\u5728Serverless\u9886\u57df\u524d\u666f\u53ef\u671f\u3002\u8fd9\u4e9b\u8bbe\u8ba1\u601d\u8def\u90fd\u503c\u5f97\u6211\u4eec\u501f\u9274\u3002<br>\u5728\u4e91\u539f\u751f\u65f6\u4ee3\uff0c\u6211\u4eec\u8981\u80fd\u591f\u5728\u6a2a\u5411\u7684\u5e94\u7528\u5f00\u53d1\u751f\u547d\u5468\u671f\u4e2d\uff0c\u5c06\u5f00\u53d1\u3001\u4ea4\u4ed8\u3001\u8fd0\u7ef4\u8fc7\u7a0b\u8fdb\u884c\u6709\u6548\u7684\u5206\u5272\u548c\u91cd\u7ec4\uff0c\u63d0\u5347\u7814\u53d1\u534f\u540c\u6548\u7387\uff1b\u5e76\u4e14\u8981\u80fd\u5728\u6574\u4e2a\u7eb5\u5411\u8f6f\u4ef6\u6280\u672f\u6808\u4e2d\uff0c\u5728\u7f16\u7a0b\u6a21\u578b\u3001\u5e94\u7528\u8fd0\u884c\u65f6\u548c\u57fa\u7840\u8bbe\u65bd\u7b49\u591a\u5c42\u9762\u8fdb\u884c\u7cfb\u7edf\u4f18\u5316\uff0c\u5b9e\u73b0radical simplification\uff0c\u63d0\u5347\u7cfb\u7edf\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bfc\u8bfb\uff1a\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u6765\u4e34\uff0c\u4e0eJava \u5f00\u53d1\u8005\u5230\u5e95\u6709\u4ec0\u4e48\u8054\u7cfb\uff1f\u6709\u4eba\u8bf4\uff0c\u4e91\u539f\u751f\u538b\u6839\u4e0d\u662f\u4e3a\u4e86Java\u5b58\u5728\u7684\u3002\u7136\u800c\uff0c\u672c\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,20],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9256"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9256"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9256\/revisions"}],"predecessor-version":[{"id":9279,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9256\/revisions\/9279"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}