{"id":119644,"date":"2026-10-30T03:00:52","date_gmt":"2026-10-29T19:00:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/119644.html"},"modified":"2026-10-30T03:00:52","modified_gmt":"2026-10-29T19:00:52","slug":"%e9%ab%98%e9%a2%91%e5%85%ab%e8%82%a1-%c2%b7-jvm%ef%bc%888%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/119644.html","title":{"rendered":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09"},"content":{"rendered":"<h2>\u9ad8\u9891\u516b\u80a1 \u00b7 JVM&#xff08;8&#xff09;&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u662f\u600e\u4e48\u88ab\u5224&#034;\u6b7b\u5211&#034;\u7684&#xff1f;<\/h2>\n<h3>\u4e00\u3001\u5f15\u7528\u8ba1\u6570 vs \u53ef\u8fbe\u6027\u5206\u6790<\/h3>\n<h4>1.1 \u5f15\u7528\u8ba1\u6570<\/h4>\n<p>\u601d\u8def&#xff1a;\u7ed9\u6bcf\u4e2a\u5bf9\u8c61\u914d\u4e00\u4e2a\u8ba1\u6570\u5668&#xff0c;\u6709\u591a\u5c11\u5f15\u7528\u6307\u5411\u6211&#xff0c;\u8ba1\u6570\u5c31\u662f\u51e0&#xff0c;\u5f52\u96f6\u5373\u5783\u573e\u3002<\/p>\n<p>\u4f18\u70b9&#xff1a;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5b9e\u65f6\u6027\u597d&#xff0c;\u5f52\u96f6\u7acb\u523b\u80fd\u6536\u3002<\/p>\n<p>\u81f4\u547d\u7f3a\u70b9&#xff1a;\u5faa\u73af\u5f15\u7528\u3002<\/p>\n<p><span class=\"token class-name\">Node<\/span> a <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Node<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\">Node<\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Node<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\na<span class=\"token punctuation\">.<\/span>next <span class=\"token operator\">&#061;<\/span> b<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ b \u7684\u8ba1\u6570 &#061; 1<\/span><br \/>\nb<span class=\"token punctuation\">.<\/span>next <span class=\"token operator\">&#061;<\/span> a<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ a \u7684\u8ba1\u6570 &#061; 1<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\nb <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u4e24\u4e2a\u5bf9\u8c61\u8ba1\u6570\u90fd\u8fd8\u662f 1&#xff0c;\u6c38\u8fdc\u6536\u4e0d\u6389<\/span><\/p>\n<p>\u5916\u9762\u5df2\u7ecf\u8bbf\u95ee\u4e0d\u5230\u5b83\u4eec\u4e86&#xff0c;\u4f46\u8ba1\u6570\u4e0d\u5f52\u96f6&#xff0c;\u6c38\u8fdc\u6cc4\u6f0f\u3002\u6240\u4ee5 HotSpot \u6ca1\u7528\u5b83\u2014\u2014\u7528\u5f15\u7528\u8ba1\u6570\u7684\u662f Python\u3001ObjC&#xff08;ARC \u662f\u7f16\u8bd1\u5668\u63d2\u6869&#xff0c;\u4e0d\u662f\u8fd0\u884c\u65f6\u7ef4\u62a4&#xff09;\u3002<\/p>\n<h4>1.2 \u53ef\u8fbe\u6027\u5206\u6790<\/h4>\n<p>\u601d\u8def&#xff1a;\u4ece\u4e00\u7ec4\u53eb GC Roots \u7684\u6839\u5bf9\u8c61\u51fa\u53d1&#xff0c;\u987a\u7740\u5f15\u7528\u94fe\u904d\u5386\u3002\u80fd\u8d70\u5230\u7684\u5c31\u662f\u6d3b\u7684&#xff0c;\u8d70\u4e0d\u5230\u7684\u5c31\u662f\u5783\u573e\u3002<\/p>\n<p>GC Roots \u2500\u2500\u2192 A \u2500\u2500\u2192 B \u2500\u2500\u2192 C    \u6d3b\u7740<br \/>\n                \u2514\u2500\u2192 D<\/p>\n<p>        E \u2500\u2500\u2192 F                \u8c01\u90fd\u8d70\u4e0d\u5230 \u2192 \u5783\u573e<\/p>\n<p>\u5929\u7136\u514d\u75ab\u5faa\u73af\u5f15\u7528\u2014\u2014\u5224\u65ad\u4f9d\u636e\u662f&#034;\u4ece\u6839\u80fd\u4e0d\u80fd\u8d70\u5230&#034;&#xff0c;\u4e0d\u662f&#034;\u6709\u51e0\u4e2a\u4eba\u6307\u7740\u6211&#034;\u3002<\/p>\n<table>\n<tr>\u5bf9\u6bd4\u9879\u5f15\u7528\u8ba1\u6570\u53ef\u8fbe\u6027\u5206\u6790<\/tr>\n<tbody>\n<tr>\n<td>\u4f9d\u636e<\/td>\n<td>\u6709\u591a\u5c11\u5f15\u7528\u6307\u5411\u6211<\/td>\n<td>\u4ece\u6839\u80fd\u5426\u8d70\u5230\u6211<\/td>\n<\/tr>\n<tr>\n<td>\u5faa\u73af\u5f15\u7528<\/td>\n<td>\u65e0\u6cd5\u56de\u6536<\/td>\n<td>\u4e0d\u53d7\u5f71\u54cd<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u673a<\/td>\n<td>\u5b9e\u65f6<\/td>\n<td>\u9700\u8981 GC \u5468\u671f<\/td>\n<\/tr>\n<tr>\n<td>\u8c01\u5728\u7528<\/td>\n<td>Python\u3001ObjC<\/td>\n<td>HotSpot<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1.3 \u4e3a\u4ec0\u4e48\u5fc5\u987b STW<\/h4>\n<p>\u904d\u5386\u5f15\u7528\u56fe\u65f6&#xff0c;\u5982\u679c\u7528\u6237\u7ebf\u7a0b\u8fd8\u5728\u6539\u5f15\u7528&#xff0c;\u5c31\u53ef\u80fd\u628a\u521a\u6302\u5230\u6839\u4e0a\u7684\u5bf9\u8c61\u8bef\u5224\u4e3a\u6b7b&#xff0c;\u76f4\u63a5\u8bef\u6740\u3002\u6240\u4ee5\u904d\u5386\u671f\u95f4\u5fc5\u987b\u51bb\u7ed3\u6240\u6709\u7528\u6237\u7ebf\u7a0b&#xff0c;\u8fd9\u4e2a\u6682\u505c\u5c31\u662f STW\u3002\u540e\u9762\u6240\u6709\u56de\u6536\u5668\u7684\u6f14\u8fdb&#xff0c;\u672c\u8d28\u4e0a\u90fd\u5728\u538b\u77ed\u8fd9\u6bb5\u65f6\u95f4\u3002<\/p>\n<h3>\u4e8c\u3001GC Roots \u6709\u54ea\u51e0\u7c7b<\/h3>\n<p>\u6839\u7684\u672c\u8d28\u4e0d\u662f&#034;\u91cd\u8981&#034;&#xff0c;\u800c\u662f&#034;\u5b83\u7684\u5b58\u6d3b\u4e0d\u7531 GC \u51b3\u5b9a&#034;\u2014\u2014\u5b83\u5728\u6808\u4e0a\u6216\u7c7b\u7ea7\u522b&#xff0c;GC \u7ba1\u4e0d\u7740&#xff0c;\u53ea\u80fd\u5f53\u8d77\u70b9\u3002<\/p>\n<table>\n<tr>\u6839\u7c7b\u578b\u5177\u4f53\u662f\u4ec0\u4e48\u751f\u547d\u5468\u671f\u7531\u8c01\u51b3\u5b9a<\/tr>\n<tbody>\n<tr>\n<td>\u865a\u62df\u673a\u6808<\/td>\n<td>\u6b63\u5728\u6267\u884c\u7684\u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\u3001\u53c2\u6570<\/td>\n<td>\u65b9\u6cd5\u662f\u5426\u8fd4\u56de<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u53d8\u91cf<\/td>\n<td>static \u5b57\u6bb5\u6307\u5411\u7684\u5bf9\u8c61<\/td>\n<td>\u7c7b\u662f\u5426\u5378\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>\u5e38\u91cf<\/td>\n<td>static final\u3001\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u7684\u5f15\u7528<\/td>\n<td>\u7c7b\u662f\u5426\u5378\u8f7d<\/td>\n<\/tr>\n<tr>\n<td>JNI \u5f15\u7528<\/td>\n<td>native \u65b9\u6cd5\u6301\u6709\u7684 Java \u5bf9\u8c61<\/td>\n<td>native \u8c03\u7528\u662f\u5426\u7ed3\u675f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8865\u5145\u6e05\u5355&#xff08;\u300a\u6df1\u5165\u7406\u89e3 Java \u865a\u62df\u673a\u300b\u91cc\u7684&#xff0c;\u7b54\u9898\u65f6\u80fd\u52a0\u5206&#xff09;&#xff1a;\u7cfb\u7edf\u7c7b\u52a0\u8f7d\u5668\u52a0\u8f7d\u7684 Class \u5bf9\u8c61\u3001\u5e38\u9a7b\u5f02\u5e38\u5bf9\u8c61&#xff08;\u5982 NPE\u3001OOM \u9884\u521b\u5efa&#xff09;\u3001\u88ab\u540c\u6b65\u9501\u6301\u6709\u7684\u5bf9\u8c61\u3001JMXBean \/ JVMTI \u56de\u8c03\u3002<\/p>\n<p>\u5b9e\u7528\u5224\u65ad\u6cd5&#xff1a;\u95ee\u4e00\u53e5&#034;\u662f\u8c01\u5728\u5f15\u7528\u5b83&#034;\u2014\u2014\u5f15\u7528\u8005\u662f\u6808\u4e0a\u7684\u53d8\u91cf&#xff0c;\u5b83\u5c31\u662f\u6839&#xff1b;\u662f\u5806\u91cc\u7684\u5bf9\u8c61&#xff0c;\u5c31\u7ee7\u7eed\u5f80\u4e0a\u8ffd\u3002<\/p>\n<h3>\u4e09\u3001\u4e0d\u53ef\u8fbe \u2260 \u7acb\u523b\u6b7b&#xff1a;\u4e24\u6b21\u6807\u8bb0<\/h3>\n<p>\u5bf9\u8c61\u88ab\u5224\u4e0d\u53ef\u8fbe\u540e&#xff0c;\u8fd8\u8981\u8fc7\u4e00\u6b21\u5ba1\u5224&#xff1a;<\/p>\n<p>\u4e0d\u53ef\u8fbe \u2192 \u7b2c\u4e00\u6b21\u6807\u8bb0<br \/>\n          \u2193<br \/>\n    \u6709 finalize() \u4e14\u4ece\u672a\u6267\u884c\u8fc7&#xff1f;<br \/>\n    \u251c\u2500 \u5426 \u2192 \u76f4\u63a5\u56de\u6536<br \/>\n    \u2514\u2500 \u662f \u2192 \u8fdb F-Queue&#xff0c;\u6267\u884c finalize()<br \/>\n              \u251c\u2500 \u91cd\u65b0\u8fde\u4e0a\u5f15\u7528\u94fe \u2192 \u9003\u8131<br \/>\n              \u2514\u2500 \u6ca1\u8fde\u4e0a \u2192 \u7b2c\u4e8c\u6b21\u6807\u8bb0 \u2192 \u56de\u6536<\/p>\n<p>\u4e09\u4e2a\u8981\u70b9&#xff1a;\u53ea\u6709\u91cd\u5199\u4e86 finalize() \u4e14\u6ca1\u6267\u884c\u8fc7\u7684\u5bf9\u8c61\u624d\u6709\u8d44\u683c\u8fdb F-Queue&#xff1b;\u5b83\u53ea\u4f1a\u88ab\u6267\u884c\u4e00\u6b21&#xff1b;\u6267\u884c\u7ebf\u7a0b\u4f18\u5148\u7ea7\u5f88\u4f4e&#xff0c;\u4e0d\u4fdd\u8bc1\u53ca\u65f6\u3002<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SaveMe<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">static<\/span> <span class=\"token class-name\">SaveMe<\/span> <span class=\"token constant\">SAVE_ME<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">finalize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u91cd\u65b0\u6302\u56de\u5f15\u7528\u94fe<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">Exception<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">SaveMe<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">gc<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token class-name\">Thread<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">500<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">?<\/span> <span class=\"token string\">&#034;\u6b7b\u4e86&#034;<\/span> <span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;\u6d3b\u4e86&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u6d3b\u4e86<\/span><\/p>\n<p>        <span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">gc<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token class-name\">Thread<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">500<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">SAVE_ME<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">?<\/span> <span class=\"token string\">&#034;\u6b7b\u4e86&#034;<\/span> <span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;\u6d3b\u4e86&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u6b7b\u4e86<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7b2c\u4e00\u6b21\u6d3b&#xff0c;\u7b2c\u4e8c\u6b21\u6b7b\u2014\u2014\u56e0\u4e3a finalize() \u53ea\u6267\u884c\u4e00\u6b21&#xff0c;\u7b2c\u4e8c\u6b21\u76f4\u63a5\u8df3\u8fc7 F-Queue\u3002<\/p>\n<h4>3.1 finalize \u4e3a\u4ec0\u4e48\u88ab\u5e9f\u5f03<\/h4>\n<p>\u4e09\u4e2a\u7406\u7531&#xff1a;\u6267\u884c\u65f6\u673a\u4e0d\u786e\u5b9a\u3001\u5355\u7ebf\u7a0b\u6267\u884c\u62d6\u6162 GC\u3001\u5f02\u5e38\u88ab\u541e\u6389\u3002<\/p>\n<ul>\n<li>JDK 9 \u6807\u8bb0 &#064;Deprecated&#xff1b;JDK 18 \u6807\u8bb0\u4e3a deprecated for removal&#xff08;JEP 421&#xff09;\u3002<\/li>\n<li>\u66ff\u4ee3\u65b9\u6848&#xff1a;\u5173\u8d44\u6e90\u7528 try-with-resources&#xff0c;\u56de\u6536\u65f6\u6e05\u7406\u672c\u5730\u8d44\u6e90\u7528 java.lang.ref.Cleaner\u2014\u2014\u5b83\u672c\u8d28\u5c31\u662f&#034;\u865a\u5f15\u7528 &#043; \u5f15\u7528\u961f\u5217&#034;\u7684\u5c01\u88c5\u3002<\/li>\n<\/ul>\n<h3>\u56db\u3001\u56db\u79cd\u5f15\u7528&#xff1a;GC \u8ba4\u4e0d\u8ba4\u8fd9\u6761\u8fb9<\/h3>\n<p>\u5f15\u7528\u5c31\u662f\u5185\u5b58\u91cc\u5b58\u653e\u5bf9\u8c61\u5730\u5740\u7684\u90a3\u51e0\u4e2a\u5b57\u8282&#xff0c;\u51fa\u73b0\u5728\u6808\u5e27\u69fd\u4f4d\u6216\u5bf9\u8c61\u5b57\u6bb5\u91cc\u3002\u8f6f\u3001\u5f31\u3001\u865a\u5f15\u7528\u5219\u662f\u5806\u91cc\u7684\u5305\u88c5\u5bf9\u8c61&#xff08;Reference \u5b50\u7c7b&#xff09;&#xff0c;\u5185\u90e8 referent \u5b57\u6bb5\u6307\u5411\u76ee\u6807&#xff0c;JVM \u5bf9\u8fd9\u4e2a\u5b57\u6bb5\u7279\u6b8a\u5904\u7406\u3002<\/p>\n<table>\n<tr>\u7c7b\u578bget()GC \u662f\u5426\u8ba4\u53ef\u8fd9\u6761\u8fb9\u56de\u6536\u65f6\u673a<\/tr>\n<tbody>\n<tr>\n<td>\u5f3a\u5f15\u7528<\/td>\n<td>\u5bf9\u8c61<\/td>\n<td>\u8ba4\u53ef<\/td>\n<td>\u4e0d\u53ef\u8fbe\u540e\u7684\u4e0b\u4e00\u6b21 GC<\/td>\n<\/tr>\n<tr>\n<td>SoftReference<\/td>\n<td>\u5bf9\u8c61\u6216 null<\/td>\n<td>\u5185\u5b58\u591f\u65f6\u8ba4\u53ef&#xff0c;\u4e0d\u591f\u65f6\u4e0d\u8ba4\u53ef<\/td>\n<td>\u5185\u5b58\u4e0d\u8db3\u65f6\u7684 GC<\/td>\n<\/tr>\n<tr>\n<td>WeakReference<\/td>\n<td>\u5bf9\u8c61\u6216 null<\/td>\n<td>\u4ece\u4e0d\u8ba4\u53ef<\/td>\n<td>\u4e0b\u4e00\u6b21 GC<\/td>\n<\/tr>\n<tr>\n<td>PhantomReference<\/td>\n<td>\u6c38\u8fdc null<\/td>\n<td>\u4ece\u4e0d\u8ba4\u53ef&#xff0c;\u56de\u6536\u540e\u5165\u961f<\/td>\n<td>\u4e0b\u4e00\u6b21 GC<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u56db\u79cd\u5f15\u7528\u7684\u771f\u6b63\u533a\u522b&#xff0c;\u5728\u4e8e GC \u8ba4\u4e0d\u8ba4\u8fd9\u6761\u5f15\u7528\u8fb9\u3002<\/p>\n<h4>4.1 \u5f3a\u5f15\u7528&#xff1a;\u5b81\u53ef OOM \u4e5f\u4e0d\u6536<\/h4>\n<p><span class=\"token class-name\">Object<\/span> o <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u53ea\u8981\u8fd9\u6761\u94fe\u8fd8\u5728&#xff0c;\u5185\u5b58\u4e0d\u591f\u4e86\u4e5f\u5b81\u53ef\u629b OOM\u3002\u6240\u8c13&#034;\u5185\u5b58\u6cc4\u6f0f&#034;&#xff0c;\u672c\u8d28\u5c31\u662f\u4e34\u65f6\u5bf9\u8c61\u88ab\u4e00\u6761\u5f3a\u5f15\u7528\u94fe\u6084\u6084\u62f4\u4f4f\u4e86\u2014\u2014\u9759\u6001\u96c6\u5408\u3001\u7f13\u5b58 Map\u3001\u6ca1 remove() \u7684 ThreadLocal&#xff0c;\u90fd\u662f\u8fd9\u4e2a\u5957\u8def\u3002<\/p>\n<h4>4.2 \u8f6f\u5f15\u7528&#xff1a;\u5185\u5b58\u4e0d\u591f\u624d\u6536<\/h4>\n<p><span class=\"token class-name\">SoftReference<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token operator\">&gt;<\/span> ref <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">SoftReference<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">10<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">1024<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">byte<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> data <span class=\"token operator\">&#061;<\/span> ref<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5185\u5b58\u591f \u2192 \u62ff\u5230&#xff1b;\u4e0d\u591f \u2192 null<\/span><\/p>\n<p>\u8bbe\u8ba1\u610f\u56fe\u662f\u505a\u7f13\u5b58\u3002\u4f46\u5b9e\u9645\u9879\u76ee\u522b\u8fd9\u4e48\u5199&#xff1a;<\/p>\n<li>\u56de\u6536\u7b56\u7565\u4e0d\u53d7\u4f60\u63a7\u5236\u3002HotSpot \u6309&#034;\u7a7a\u95f2\u5806 \u00d7 -XX:SoftRefLRUPolicyMSPerMB&#034;&#xff08;\u9ed8\u8ba4 1000&#xff0c;\u5373\u6bcf MB \u7a7a\u95f2\u5806\u6362 1 \u79d2&#xff09;\u7b97\u5b58\u6d3b\u65f6\u95f4&#xff0c;\u4e00\u6b21 Full GC \u540e\u7a7a\u95f2\u5806\u53d8\u5c0f&#xff0c;\u7f13\u5b58\u4f1a\u6210\u7247\u6d88\u5931&#xff1b;<\/li>\n<li>\u4f60\u60f3\u6309 LRU \u6dd8\u6c70\u70ed\u70b9&#xff0c;\u5b83\u6309\u5185\u5b58\u6c34\u4f4d\u4e00\u628a\u6e05\u7a7a\u3002<\/li>\n<p>\u4e1a\u52a1\u7f13\u5b58\u8001\u5b9e\u7528 Caffeine \/ Guava&#xff08;\u5f3a\u5f15\u7528 &#043; \u5bb9\u91cf\u6dd8\u6c70&#xff09;\u3002<\/p>\n<h4>4.3 \u5f31\u5f15\u7528&#xff1a;\u4e0b\u6b21 GC \u5fc5\u6536<\/h4>\n<p>\u4e0d\u7ba1\u5185\u5b58\u591f\u4e0d\u591f&#xff0c;\u53ea\u8981 GC \u5c31\u56de\u6536\u3002<\/p>\n<p>\u6700\u7ecf\u5178\u7684\u5e94\u7528\u662f ThreadLocal \u7684 Entry&#xff1a;<\/p>\n<p><span class=\"token keyword\">static<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Entry<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">WeakReference<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">ThreadLocal<\/span><span class=\"token punctuation\">&lt;<\/span><span class=\"token operator\">?<\/span><span class=\"token punctuation\">&gt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">Object<\/span> value<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token class-name\">Entry<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ThreadLocal<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token operator\">?<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> k<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span> v<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">super<\/span><span class=\"token punctuation\">(<\/span>k<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ key \u5f31\u5f15\u7528<\/span><br \/>\n        value <span class=\"token operator\">&#061;<\/span> v<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ value \u5f3a\u5f15\u7528<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u7528\u5f31\u5f15\u7528&#xff1a;ThreadLocal \u5bf9\u8c61\u901a\u5e38\u88ab\u7ebf\u7a0b\u7684 ThreadLocalMap \u6301\u6709&#xff0c;\u5982\u679c key \u662f\u5f3a\u5f15\u7528&#xff0c;\u7ebf\u7a0b\u4e0d\u6b7b\u5b83\u5c31\u6c38\u8fdc\u4e0d\u56de\u6536\u3002<\/p>\n<p>\u4f46\u5f31\u5f15\u7528\u5e26\u6765\u65b0\u95ee\u9898&#xff1a;key \u88ab\u56de\u6536\u540e\u53d8\u6210 null&#xff0c;value \u8fd8\u662f\u5f3a\u5f15\u7528&#xff0c;\u8fd9\u6761 Entry \u53d8\u6210 key&#061;null \u7684\u810f Entry&#xff0c;\u8bbf\u95ee\u4e0d\u5230\u5374\u5360\u7740\u5185\u5b58\u3002<\/p>\n<p>\u5b8c\u6574\u56e0\u679c\u94fe&#xff1a;key \u5f31\u5f15\u7528\u88ab\u56de\u6536 \u2192 \u7559\u4e0b null key \u7684 Entry \u2192 value \u5f3a\u5f15\u7528\u65e0\u6cd5\u91ca\u653e \u2192 \u6cc4\u6f0f\u3002<br \/>\n\u6240\u4ee5 ThreadLocal \u7528\u5b8c\u5fc5\u987b remove()&#xff1b;\u6e90\u7801\u91cc set\/get\/remove \u4f1a\u987a\u624b\u6e05\u4e00\u90e8\u5206&#xff0c;\u4f46\u4e0d\u4fdd\u8bc1\u6e05\u5e72\u51c0\u3002<\/p>\n<p>\u5176\u4ed6\u7528\u6cd5&#xff1a;WeakHashMap\u3001Guava \u7684 weakKeys()\u3001\u5404\u79cd\u76d1\u542c\u5668\u6ce8\u518c\u8868\u3002<\/p>\n<h4>4.4 \u865a\u5f15\u7528&#xff1a;\u53ea\u4e3a&#034;\u6536\u5c38\u901a\u77e5&#034;<\/h4>\n<p>\u4e09\u4e2a\u7279\u70b9&#xff1a;get() \u6c38\u8fdc\u8fd4\u56de null&#xff1b;\u5fc5\u987b\u914d\u5408 ReferenceQueue&#xff1b;\u552f\u4e00\u4f5c\u7528\u662f\u5bf9\u8c61\u88ab\u56de\u6536\u65f6\u6536\u5230\u901a\u77e5\u3002<\/p>\n<p><span class=\"token class-name\">ReferenceQueue<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> queue <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ReferenceQueue<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\">PhantomReference<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> ref <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">PhantomReference<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Object<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> queue<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">gc<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nqueue<span class=\"token punctuation\">.<\/span><span class=\"token function\">remove<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1000<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u6536\u5230\u901a\u77e5<\/span><br \/>\nref<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>               <span class=\"token comment\">\/\/ \u6c38\u8fdc null<\/span><\/p>\n<p>\u5178\u578b\u573a\u666f&#xff1a;DirectByteBuffer \u56de\u6536\u5806\u5916\u5185\u5b58\u3002<\/p>\n<p>allocateDirect() \u7684\u5185\u5b58\u4e0d\u5728\u5806\u91cc&#xff0c;GC \u7ba1\u4e0d\u7740\u3002JDK \u7684\u505a\u6cd5\u662f\u6302\u4e00\u4e2a Cleaner&#xff08;PhantomReference \u7684\u5b50\u7c7b&#xff09;&#xff0c;\u7b49 DirectByteBuffer \u5bf9\u8c61\u88ab\u56de\u6536\u65f6\u865a\u5f15\u7528\u5165\u961f&#xff0c;Cleaner \u7ebf\u7a0b\u6536\u5230\u901a\u77e5&#xff0c;\u8c03\u7528 Unsafe.freeMemory() \u628a\u5806\u5916\u5185\u5b58\u8fd8\u56de\u53bb\u3002<\/p>\n<p>\u8fd9\u4e5f\u89e3\u91ca\u4e86&#034;\u5806\u5185\u5b58\u5f88\u5065\u5eb7&#xff0c;\u4f46\u8fdb\u7a0b RSS \u4e00\u76f4\u6da8&#034;\u2014\u2014\u5806\u5916\u5185\u5b58\u7684\u91ca\u653e\u4f9d\u8d56 GC \u89e6\u53d1&#xff0c;\u5bf9\u8c61\u4e0d\u6536&#xff0c;\u5806\u5916\u5c31\u4e0d\u8fd8\u3002<\/p>\n<h3>\u4e94\u3001\u4e24\u4e2a\u5bb9\u6613\u7b54\u9519\u7684\u7ec6\u8282<\/h3>\n<p>1. &#034;\u4e0d\u53ef\u8fbe&#034;\u548c&#034;\u88ab\u56de\u6536&#034;\u4e0d\u662f\u540c\u4e00\u65f6\u523b\u3002 \u5224\u65ad\u4e0d\u53ef\u8fbe\u53ea\u5728 GC \u8dd1\u53ef\u8fbe\u6027\u5206\u6790\u65f6\u624d\u505a&#xff0c;\u6240\u4ee5\u4ece&#034;\u6ca1\u4eba\u5f15\u7528&#034;\u5230&#034;\u771f\u6b63\u56de\u6536&#034;\u4e2d\u95f4\u81f3\u5c11\u9694\u7740\u4e00\u6b21 GC&#xff1b;\u8f6f\/\u5f31\/\u865a\u5f15\u7528\u5168\u90fd\u662f&#034;\u4e0b\u6b21 GC \u624d\u56de\u6536&#034;\u3002<\/p>\n<p>2. \u5f15\u7528\u961f\u5217\u662f&#034;\u88ab\u52a8\u901a\u77e5&#034;&#xff0c;get() \u662f&#034;\u4e3b\u52a8\u67e5\u8be2&#034;\u3002 \u5bf9\u8c61\u88ab\u56de\u6536\u65f6&#xff0c;JVM \u628a Reference \u5bf9\u8c61\u672c\u8eab\u585e\u8fdb\u961f\u5217\u3002\u865a\u5f15\u7528 get() \u6c38\u8fdc null&#xff0c;\u53ea\u80fd\u9760\u961f\u5217&#xff1b;WeakHashMap \u4e5f\u662f\u9760\u961f\u5217\u77e5\u9053&#034;\u54ea\u6761 Entry \u8be5\u5220\u4e86&#034;\u3002<\/p>\n<p>\u6240\u4ee5&#034;\u5f31\u5f15\u7528\u4f1a\u81ea\u52a8\u6e05\u7406&#034;\u8fd9\u8bdd\u4e0d\u51c6\u786e\u2014\u2014\u5f31\u5f15\u7528\u53ea\u8d1f\u8d23\u8ba9 key \u53d8 null&#xff0c;\u6e05\u7406\u52a8\u4f5c\u662f WeakHashMap \u81ea\u5df1\u505a\u7684\u3002\u8fd9\u662f\u4e2a\u5f88\u597d\u7684\u52a0\u5206\u70b9\u3002<\/p>\n<h3>\u516d\u3001\u9ad8\u9891\u9762\u8bd5\u9898\u901f\u7b54<\/h3>\n<p>Q1&#xff1a;\u600e\u4e48\u5224\u65ad\u5bf9\u8c61\u662f\u5783\u573e&#xff1f;<br \/>\n\u5f15\u7528\u8ba1\u6570&#xff08;\u5f52\u96f6\u5373\u5783\u573e&#xff09;\u548c\u53ef\u8fbe\u6027\u5206\u6790&#xff08;\u4ece GC Roots \u8d70\u4e0d\u5230\u5373\u5783\u573e&#xff09;\u3002HotSpot \u7528\u540e\u8005&#xff0c;\u56e0\u4e3a\u524d\u8005\u89e3\u51b3\u4e0d\u4e86\u5faa\u73af\u5f15\u7528\u3002<\/p>\n<p>Q2&#xff1a;GC Roots \u6709\u54ea\u51e0\u7c7b&#xff1f;<br \/>\n\u865a\u62df\u673a\u6808\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u548c\u53c2\u6570\u3001\u9759\u6001\u53d8\u91cf\u3001\u5e38\u91cf\u3001JNI \u5f15\u7528\u3002\u6269\u5c55\u8fd8\u6709\u7cfb\u7edf\u7c7b\u52a0\u8f7d\u5668\u7684 Class \u5bf9\u8c61\u3001\u5e38\u9a7b\u5f02\u5e38\u5bf9\u8c61\u3001\u540c\u6b65\u9501\u6301\u6709\u5bf9\u8c61\u7b49\u3002<\/p>\n<p>Q3&#xff1a;\u53ef\u8fbe\u6027\u5206\u6790\u4e3a\u4ec0\u4e48\u8981 STW&#xff1f;<br \/>\n\u904d\u5386\u671f\u95f4\u7528\u6237\u7ebf\u7a0b\u6539\u5f15\u7528&#xff0c;\u53ef\u80fd\u628a\u6d3b\u5bf9\u8c61\u8bef\u5224\u4e3a\u6b7b\u5bf9\u8c61\u800c\u8bef\u6740&#xff0c;\u6240\u4ee5\u5fc5\u987b\u51bb\u7ed3\u5f15\u7528\u56fe\u3002<\/p>\n<p>Q4&#xff1a;\u4e0d\u53ef\u8fbe\u4e00\u5b9a\u88ab\u56de\u6536\u5417&#xff1f;<br \/>\n\u4e0d\u4e00\u5b9a\u3002\u91cd\u5199\u4e86 finalize() \u4e14\u6ca1\u6267\u884c\u8fc7\u7684\u4f1a\u8fdb F-Queue&#xff0c;\u80fd\u91cd\u65b0\u8fde\u4e0a\u5f15\u7528\u94fe\u5c31\u6d3b\u4e0b\u6765&#xff1b;\u5426\u5219\u76f4\u63a5\u56de\u6536\u3002<\/p>\n<p>Q5&#xff1a;finalize \u80fd\u6551\u51e0\u6b21&#xff1f;<br \/>\n\u4e00\u6b21\u3002\u5b83\u53ea\u4f1a\u88ab\u6267\u884c\u4e00\u6b21&#xff0c;\u7b2c\u4e8c\u6b21\u4e0d\u53ef\u8fbe\u5c31\u76f4\u63a5\u56de\u6536\u3002<\/p>\n<p>Q6&#xff1a;\u56db\u79cd\u5f15\u7528\u533a\u522b&#xff1f;<br \/>\n\u5f3a\u5f15\u7528\u6c38\u4e0d\u56de\u6536&#xff08;\u5b81\u53ef OOM&#xff09;&#xff1b;\u8f6f\u5f15\u7528\u5185\u5b58\u4e0d\u8db3\u65f6\u56de\u6536&#xff1b;\u5f31\u5f15\u7528\u4e0b\u6b21 GC \u5fc5\u56de\u6536&#xff1b;\u865a\u5f15\u7528\u53ea\u7528\u4e8e\u56de\u6536\u901a\u77e5&#xff0c;get() \u6c38\u8fdc null\u3002<\/p>\n<p>Q7&#xff1a;ThreadLocal \u4e3a\u4ec0\u4e48\u5185\u5b58\u6cc4\u6f0f&#xff1f;<br \/>\nEntry \u7684 key \u662f\u5f31\u5f15\u7528\u3001value \u662f\u5f3a\u5f15\u7528\u3002key \u88ab\u56de\u6536\u540e\u53d8 null&#xff0c;value \u4ecd\u88ab\u5f3a\u5f15\u7528&#xff0c;\u5f62\u6210\u8bbf\u95ee\u4e0d\u5230\u4e5f\u91ca\u653e\u4e0d\u4e86\u7684\u810f Entry\u3002\u7528\u5b8c\u8981 remove()\u3002<\/p>\n<p>Q8&#xff1a;\u865a\u5f15\u7528\u80fd\u505a\u4ec0\u4e48&#xff1f;<br \/>\n\u53ea\u505a&#034;\u56de\u6536\u901a\u77e5&#034;\u3002\u5178\u578b\u662f DirectByteBuffer \u901a\u8fc7 Cleaner \u91ca\u653e\u5806\u5916\u5185\u5b58\u3002<\/p>\n<h3>\u4e03\u3001\u4e00\u53e5\u8bdd\u603b\u7ed3<\/h3>\n<p>HotSpot \u7528\u53ef\u8fbe\u6027\u5206\u6790\u5224\u6b7b&#xff0c;\u4ece GC Roots \u8d70\u4e0d\u5230\u5c31\u662f\u5783\u573e&#xff1b;\u4f46&#034;\u4e0d\u53ef\u8fbe&#034;\u53ea\u662f&#034;\u53ef\u4ee5\u6b7b\u4e86&#034;&#xff0c;\u8fd8\u8981\u8fc7 finalize \u8fd9\u4e00\u5173&#xff0c;\u800c\u4e14\u53ea\u6709\u4e00\u6b21\u673a\u4f1a\u3002\u56db\u79cd\u5f15\u7528\u7684\u533a\u522b&#xff0c;\u672c\u8d28\u662f GC \u8ba4\u4e0d\u8ba4\u8fd9\u6761\u5f15\u7528\u8fb9\u2014\u2014\u5f3a\u5f15\u7528\u6c38\u4e0d\u653e\u624b&#xff0c;\u8f6f\u5f15\u7528\u770b\u5185\u5b58\u8138\u8272&#xff0c;\u5f31\u5f15\u7528\u4e0b\u6b21 GC \u5c31\u8d70&#xff0c;\u865a\u5f15\u7528\u53ea\u8d1f\u8d23\u53d1\u8ba3\u544a\u3002<\/p>\n<p>\u4e0b\u4e00\u671f\u8bb2\u56de\u6536\u7684&#034;\u624b\u6cd5&#034;&#xff1a;\u4e09\u79cd\u56de\u6536\u7b97\u6cd5\u600e\u4e48\u53d6\u820d\u30018:1:1 \u5230\u5e95\u662f\u600e\u4e48\u6765\u7684\u3001\u8de8\u4ee3\u5f15\u7528\u600e\u4e48\u7528\u5361\u8868 &#043; \u5199\u5c4f\u969c\u89e3\u51b3&#xff0c;\u987a\u5e26\u628a\u4e09\u8272\u6807\u8bb0\u7684\u4e24\u4e2a\u7ecf\u5178\u95ee\u9898\u8bb2\u6e05\u695a\u3002<\/p>\n<hr \/>\n<p>&#xff08;\u672c\u7cfb\u5217\u6301\u7eed\u66f4\u65b0\u4e2d&#xff0c;\u5171 10 \u671f&#xff0c;\u656c\u8bf7\u5173\u6ce8&#xff5e;&#xff09;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9ad8\u9891\u516b\u80a1 \u00b7 JVM&#xff08;8&#xff09;&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u662f\u600e\u4e48\u88ab\u5224\\&#8221;\u6b7b\u5211\\&#8221;\u7684&#xff1f;<br \/>\n\u4e00\u3001\u5f15\u7528\u8ba1\u6570 vs \u53ef\u8fbe\u6027\u5206\u6790<br \/>\n1.1 \u5f15\u7528\u8ba1\u6570<br \/>\n\u601d\u8def&#xff1a;\u7ed9\u6bcf\u4e2a\u5bf9\u8c61\u914d\u4e00\u4e2a\u8ba1\u6570\u5668&#xff0c;\u6709\u591a\u5c11\u5f15\u7528\u6307\u5411\u6211&#xff0c;\u8ba1\u6570\u5c31\u662f\u51e0&#xff0c;\u5f52\u96f6\u5373\u5783\u573e\u3002<br \/>\n\u4f18\u70b9&#xff1a;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5b9e\u65f6\u6027\u597d&#xff0c;\u5f52\u96f6\u7acb\u523b\u80fd\u6536\u3002<br \/>\n\u81f4\u547d\u7f3a\u70b9&#xff1a;\u5faa\u73af\u5f15\u7528\u3002<br \/>\nNode a  new Node();<br \/>\nNode b  new <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13645,99,426,1833,176],"topic":[],"class_list":["post-119644","post","type-post","status-publish","format-standard","hentry","category-server","tag-13645","tag-java","tag-jvm","tag-1833","tag-176"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/119644.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM&#xff08;8&#xff09;&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u662f\u600e\u4e48\u88ab\u5224&quot;\u6b7b\u5211&quot;\u7684&#xff1f; \u4e00\u3001\u5f15\u7528\u8ba1\u6570 vs \u53ef\u8fbe\u6027\u5206\u6790 1.1 \u5f15\u7528\u8ba1\u6570 \u601d\u8def&#xff1a;\u7ed9\u6bcf\u4e2a\u5bf9\u8c61\u914d\u4e00\u4e2a\u8ba1\u6570\u5668&#xff0c;\u6709\u591a\u5c11\u5f15\u7528\u6307\u5411\u6211&#xff0c;\u8ba1\u6570\u5c31\u662f\u51e0&#xff0c;\u5f52\u96f6\u5373\u5783\u573e\u3002 \u4f18\u70b9&#xff1a;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5b9e\u65f6\u6027\u597d&#xff0c;\u5f52\u96f6\u7acb\u523b\u80fd\u6536\u3002 \u81f4\u547d\u7f3a\u70b9&#xff1a;\u5faa\u73af\u5f15\u7528\u3002 Node a new Node(); Node b new\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/119644.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-29T19:00:52+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119644.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/119644.html\",\"name\":\"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-29T19:00:52+00:00\",\"dateModified\":\"2026-10-29T19:00:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/119644.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/119644.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/119644.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/119644.html","og_locale":"zh_CN","og_type":"article","og_title":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM&#xff08;8&#xff09;&#xff1a;\u4e00\u4e2a\u5bf9\u8c61\u662f\u600e\u4e48\u88ab\u5224\"\u6b7b\u5211\"\u7684&#xff1f; \u4e00\u3001\u5f15\u7528\u8ba1\u6570 vs \u53ef\u8fbe\u6027\u5206\u6790 1.1 \u5f15\u7528\u8ba1\u6570 \u601d\u8def&#xff1a;\u7ed9\u6bcf\u4e2a\u5bf9\u8c61\u914d\u4e00\u4e2a\u8ba1\u6570\u5668&#xff0c;\u6709\u591a\u5c11\u5f15\u7528\u6307\u5411\u6211&#xff0c;\u8ba1\u6570\u5c31\u662f\u51e0&#xff0c;\u5f52\u96f6\u5373\u5783\u573e\u3002 \u4f18\u70b9&#xff1a;\u5b9e\u73b0\u7b80\u5355&#xff0c;\u5b9e\u65f6\u6027\u597d&#xff0c;\u5f52\u96f6\u7acb\u523b\u80fd\u6536\u3002 \u81f4\u547d\u7f3a\u70b9&#xff1a;\u5faa\u73af\u5f15\u7528\u3002 Node a new Node(); Node b new","og_url":"https:\/\/www.wsisp.com\/helps\/119644.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-29T19:00:52+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/119644.html","url":"https:\/\/www.wsisp.com\/helps\/119644.html","name":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-29T19:00:52+00:00","dateModified":"2026-10-29T19:00:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/119644.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/119644.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/119644.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u9ad8\u9891\u516b\u80a1 \u00b7 JVM\uff088\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=119644"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/119644\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=119644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=119644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=119644"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=119644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}