{"id":216129,"date":"2021-04-27T08:48:14","date_gmt":"2021-04-27T00:48:14","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=216129"},"modified":"2021-04-16T14:48:39","modified_gmt":"2021-04-16T06:48:39","slug":"java-threads-and-processes","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/java-threads-and-processes.html","title":{"rendered":"\u533a\u5206Java\u7ebf\u7a0b\u4e0e\u8fdb\u7a0b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7ebf\u7a0b\uff1f\u8fdb\u7a0b\uff1f\u4f1a\u4e0d\u4f1a\u50bb\u50bb\u5206\u4e0d\u6e05\u695a\uff1f\u5e94\u8be5\u5982\u4f55\u66f4\u597d\u7684\u53bb\u7406\u89e3JAVA\u4e2d\u7684\u7ebf\u7a0b\u8fdb\u7a0b\u4ece\u800c\u5c06\u4ed6\u4eec\u7684\u4ef7\u503c\u4f5c\u7528\u6709\u6548\u53d1\u6325\u5230\u6781\u81f4\u5462\u3002\u63a5\u7740\u5f80\u4e0b\u770b\u5427\uff0c\u6700\u8be6\u7ec6\u7684\u7ebf\u7a0b\u8fdb\u7a0b\u4ecb\u7ecd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5728JAVA\u4e2d\u51e0\u4e4e\u4efb\u4f55\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u652f\u6301\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\uff0c\u901a\u5e38\u4e00\u4e2a\u4efb\u52a1\u5c31\u662f\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u800c\u4e00\u4e2a\u7a0b\u5e8f\u5c31\u662f\u4e00\u4e2a\u8fdb\u7a0b\u3002\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u65f6\uff0c\u5185\u90e8\u53ef\u80fd\u5305\u62ec\u591a\u4e2a\u987a\u5e8f\u6267\u884c\u6d41\uff0c\u6bcf\u4e2a\u987a\u5e8f\u6267\u884c\u6d41\u5c31\u662f\u4e00\u4e2a\u7ebf\u7a0b\u3002<\/p>\n

\"\"<\/p>\n

\u4e00\u3001\u4ec0\u4e48\u662f\u8fdb\u7a0b<\/strong><\/div>\n

\u8fdb\u7a0b\u662f\u8d44\u6e90(CPU\u3001\u5185\u5b58\u7b49)\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u5b83\u662f\u7a0b\u5e8f\u6267\u884c\u65f6\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7cfb\u7edf\u5c31\u4f1a\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u5e76\u4e3a\u5b83\u5206\u914d\u8d44\u6e90\uff0c\u7136\u540e\u628a\u8be5\u8fdb\u7a0b\u653e\u5165\u8fdb\u7a0b\u5c31\u7eea\u961f\u5217\uff0c\u8fdb\u7a0b\u8c03\u5ea6\u5668\u9009\u4e2d\u5b83\u7684\u65f6\u5019\u5c31\u4f1a\u4e3a\u5b83\u5206\u914dCPU\u65f6\u95f4\uff0c\u7a0b\u5e8f\u5f00\u59cb\u771f\u6b63\u8fd0\u884c\u3002\u8fdb\u7a0b\u7684\u4f18\u70b9\u662f\u63d0\u9ad8CPU\u8fd0\u884c\u6548\u7387\uff0c\u5728\u540c\u4e00\u65f6\u95f4\u5185\u6267\u884c\u591a\u4e2a\u7a0b\u5e8f\uff0c\u5373\u5e76\u53d1\u6267\u884c\u3002\u4f46\u662f\u4ece\u4e25\u683c\u4e0a\u8bb2,\u4e5f\u4e0d\u662f\u7edd\u5bf9\u7684\u540c\u4e00\u65f6\u523b\u6267\u884c\u591a\u4e2a\u7a0b\u5e8f\uff0c\u53ea\u4e0d\u8fc7CPU\u5728\u6267\u884c\u65f6\u901a\u8fc7\u65f6\u95f4\u7247\u7b49\u8c03\u5ea6\u7b97\u6cd5\u4e0d\u540c\u8fdb\u7a0b\u9ad8\u901f\u5207\u6362\u3002\u8fdb\u7a0b\u7c7b\u4f3c\u4e8e\u4eba\u7c7b\uff0c\u662f\u88ab\u4ea7\u751f\u7684\uff0c\u6709\u6216\u957f\u6216\u77ed\u7684\u6709\u6548\u751f\u547d\uff0c\u53ef\u4ee5\u4ea7\u751f\u4e00\u4e2a\u6216\u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u6700\u7ec8\u90fd\u8981\u6d88\u4ea1\u7684\u3002\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u90fd\u53ea\u6709\u4e00\u4e2a\u7236\u8fdb\u7a0b\u3002\u5728\u8fd9\u91cc\u987a\u5e26\u63d0\u4e0b\uff0cLinux\u91cc\u901a\u8fc7\u8c03\u7528fork()\u51fd\u6570\u4ea7\u751f\u5b50\u8fdb\u7a0b\u3002\u5b50\u8fdb\u7a0b\u5728\u521b\u5efa\u65f6\uff0c\u5b83\u51e0\u4e4e\u548c\u7236\u8fdb\u7a0b\u76f8\u540c\u3002\u5b83\u662f\u4ece\u7236\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4copy\u8fc7\u6765\u7684\u3002\u5c3d\u7ba1\u5b83\u4eec\u53ef\u4ee5\u5171\u4eab\u6709\u7a0b\u5e8f\u4ee3\u7801\u7684\u9875\uff0c\u4f46\u662f\u5b83\u4eec\u5404\u81ea\u6709\u72ec\u7acb\u7684\u6570\u636e\u7a7a\u95f4\u3002\u5bf9\u5b50\u8fdb\u7a0b\u5185\u5b58\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u7236\u8fdb\u7a0b\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<\/p>\n

\u4e8c\u3001 \u4ec0\u4e48\u662f\u7ebf\u7a0b<\/strong><\/div>\n

\u7ebf\u7a0b\u662f\u4e00\u6761\u6267\u884c\u8def\u5f84\uff0c\u662f\u7a0b\u5e8f\u6267\u884c\u65f6\u7684\u6700\u5c0f\u5355\u4f4d\uff0c\u5b83\u662f\u8fdb\u7a0b\u7684\u4e00\u4e2a\u6267\u884c\u6d41\uff0c\u662fCPU\u8c03\u5ea6\u548c\u5206\u6d3e\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u7531\u5f88\u591a\u4e2a\u7ebf\u7a0b\u7ec4\u6210\uff0c\u7ebf\u7a0b\u95f4\u5171\u4eab\u8fdb\u7a0b\u7684\u6240\u6709\u8d44\u6e90\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u6709\u81ea\u5df1\u7684\u5806\u6808\u548c\u5c40\u90e8\u53d8\u91cf\u3002\u7ebf\u7a0b\u7531CPU\u72ec\u7acb\u8c03\u5ea6\u6267\u884c\uff0c\u5728\u591aCPU\u73af\u5883\u4e0b\u5c31\u5141\u8bb8\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8fd0\u884c\u3002\u540c\u6837\u591a\u7ebf\u7a0b\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u5e76\u53d1\u64cd\u4f5c\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u5206\u914d\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\u3002\u7ebf\u7a0b\u662f\u4e00\u6761\u53ef\u4ee5\u6267\u884c\u7684\u8def\u5f84\u3002\u591a\u7ebf\u7a0b\u5c31\u662f\u540c\u65f6\u6709\u591a\u6761\u6267\u884c\u8def\u5f84\u5728\u540c\u65f6(\u5e76\u884c)\u6267\u884c\u3002<\/p>\n

\u4e09\u3001\u7ebf\u7a0b\u4e0e\u8fdb\u7a0b\u7684\u7279\u70b9<\/strong><\/div>\n
(1)\u8fdb\u7a0b\u7279\u70b9\uff1a<\/strong><\/span><\/div>\n

1\uff1a\u72ec\u7acb\u6027\uff1a\u8fdb\u7a0b\u662f\u7cfb\u7edf\u4e2d\u72ec\u7acb\u5b58\u5728\u7684\u5b9e\u4f53\uff0c\u5b83\u53ef\u4ee5\u72ec\u7acb\u62e5\u6709\u8d44\u6e90\uff0c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u6ca1\u6709\u8fdb\u7a0b\u672c\u8eab\u7684\u8fd0\u884c\uff0c\u7528\u6237\u8fdb\u7a0b\u4e0d\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u5176\u4ed6\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u3002<\/p>\n

2\uff1a\u52a8\u6001\u6027\uff1a\u8fdb\u7a0b\u548c\u7a0b\u5e8f\u7684\u533a\u522b\u5728\u4e8e\u8fdb\u7a0b\u662f\u52a8\u6001\u7684\uff0c\u8fdb\u7a0b\u4e2d\u6709\u65f6\u95f4\u7684\u6982\u5ff5\uff0c\u8fdb\u7a0b\u5177\u6709\u81ea\u5df1\u7684\u751f\u547d\u5468\u671f\u548c\u5404\u79cd\u4e0d\u540c\u7684\u72b6\u6001\u3002<\/p>\n

3\uff1a\u5e76\u53d1\u6027\uff1a\u591a\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u5728\u5355\u4e2a\u5904\u7406\u5668\u4e0a\u5e76\u53d1\u6267\u884c\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n

(2)\u7ebf\u7a0b\u7279\u70b9<\/strong><\/span><\/div>\n

1\uff1a\u8f7b\u578b\u5b9e\u4f53<\/p>\n

\u7ebf\u7a0b\u4e2d\u7684\u5b9e\u4f53\u5355\u4f4d\u57fa\u672c\u4e0a\u4e0d\u62e5\u6709\u7cfb\u7edf\u8d44\u6e90\uff0c\u53ea\u662f\u6709\u4e00\u70b9\u5fc5\u4e0d\u53ef\u5c11\u7684\u3001\u80fd\u4fdd\u8bc1\u72ec\u7acb\u8fd0\u884c\u7684\u8d44\u6e90\u3002\u7ebf\u7a0b\u7684\u5b9e\u4f53\u5305\u62ec\u7a0b\u5e8f\u3001\u6570\u636e\u548cTCB\u3002\u7ebf\u7a0b\u662f\u52a8\u6001\u6982\u5ff5\uff0c\u4ed6\u7684\u52a8\u6001\u7279\u6027\u7531\u7ebf\u7a0b\u63a7\u5236\u5757TCB\u63cf\u8ff0\u3002<\/p>\n

2\uff1a\u72ec\u7acb\u8c03\u5ea6\u548c\u5206\u6d3e\u7684\u57fa\u672c\u5355\u4f4d<\/p>\n

\u518d\u591a\u7ebf\u7a0bOS\u4e2d\uff0c\u7ebf\u7a0b\u662f\u80fd\u72ec\u7acb\u8fd0\u884c\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u56e0\u800c\u4e5f\u662f\u72ec\u7acb\u8c03\u5ea6\u548c\u5206\u6d3e\u7684\u57fa\u672c\u5355\u4f4d\u3002\u4f46\u7531\u4e8e\u7ebf\u7a0b\u5f88\u201c\u8f7b\u201d\uff0c\u6545\u7ebf\u7a0b\u7684\u5207\u6362\u975e\u5e38\u8fc5\u901f\u4e14\u5f00\u9500\u5c0f(\u5728\u7edf\u4e00\u8fdb\u7a0b\u4e2d\u7684)\u3002<\/p>\n

3\uff1a\u53ef\u5e76\u53d1\u6267\u884c<\/p>\n

\u5728\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\u7684\u591a\u4e2a\u7ebf\u7a0b\u4e4b\u95f4\uff0c\u53ef\u4ee5\u5e76\u53d1\u6267\u884c\uff0c\u751a\u81f3\u5141\u8bb8\u5728\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\u6240\u6709\u7ebf\u7a0b\u90fd\u80fd\u5e76\u53d1\u6267\u884c;\u540c\u6837\uff0c\u4e0d\u540c\u8fdb\u7a0b\u4e2d\u7684\u7ebf\u7a0b\u4e5f\u80fd\u5e76\u53d1\u6267\u884c\uff0c\u5145\u5206\u5229\u7528\u548c\u53d1\u6325\u4e86\u5904\u7406\u673a\u4e0e\u5916\u56f4\u8bbe\u5907\u5e76\u884c\u5de5\u4f5c\u7684\u80fd\u529b\u3002<\/p>\n

4\uff1a\u5171\u4eab\u8fdb\u7a0b\u8d44\u6e90<\/p>\n

\u5728\u540c\u4e00\u8fdb\u7a0b\u4e2d\u7684\u5404\u4e2a\u7ebf\u7a0b\uff0c\u90fd\u53ef\u4ee5\u5171\u4eab\u8be5\u8fdb\u7a0b\u6240\u62e5\u6709\u7684\u8d44\u6e90\uff0c\u8fd9\u9996\u5148\u8868\u73b0\u5728\uff1a\u6240\u6709\u7ebf\u7a0b\u90fd\u5177\u6709\u76f8\u540c\u7684\u5730\u5740\u7a7a\u95f4(\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4)\uff0c\u8fd9\u610f\u5473\u8005\uff0c\u7ebf\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u8be5\u5730\u5740\u7a7a\u95f4\u7684\u6bcf\u4e00\u4e2a\u865a\u5730\u5740;\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u8bbf\u95ee\u8be5\u8fdb\u7a0b\u6240\u62e5\u6709\u7684\u5df2\u6253\u5f00\u6587\u4ef6\u3001\u5b9a\u65f6\u5668\u3001\u4fe1\u53f7\u91cf\u673a\u6784\u7b49\u3002\u7531\u4e8e\u540c\u4e00\u4e2a\u8fdb\u7a0b\u5185\u7684\u7ebf\u7a0b\u5171\u4eab\u5185\u5b58\u548c\u6587\u4ef6\uff0c\u6240\u4ee5\u7ebf\u7a0b\u4e4b\u95f4\u4e92\u76f8\u901a\u4fe1\u4e0d\u5fc5\u8c03\u7528\u5185\u6838\u3002<\/p>\n

\u56db\u3001\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u7684\u533a\u522b\uff1a<\/strong><\/div>\n

1\u3001\u5bb9\u6613\u521b\u5efa\u65b0\u7ebf\u7a0b\u3002\u4f46\u662f\uff0c\u521b\u5efa\u65b0\u8fdb\u7a0b\u9700\u8981\u91cd\u590d\u7236\u8fdb\u7a0b\u3002<\/p>\n

2\u3001\u7ebf\u7a0b\u53ef\u4ee5\u63a7\u5236\u540c\u4e00\u8fdb\u7a0b\u7684\u5176\u4ed6\u7ebf\u7a0b\u3002\u8fdb\u7a0b\u65e0\u6cd5\u63a7\u5236\u5144\u5f1f\u8fdb\u7a0b\uff0c\u53ea\u80fd\u63a7\u5236\u5176\u5b50\u8fdb\u7a0b\u3002<\/p>\n

3\u3001\u8fdb\u7a0b\u62e5\u6709\u81ea\u5df1\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u7ebf\u7a0b\u4f7f\u7528\u8fdb\u7a0b\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u4e14\u8981\u548c\u8be5\u8fdb\u7a0b\u7684\u5176\u4ed6\u7ebf\u7a0b\u5171\u4eab\u8fd9\u4e2a\u7a7a\u95f4;\u800c\u4e0d\u662f\u5728\u8fdb\u7a0b\u4e2d\u7ed9\u6bcf\u4e2a\u7ebf\u7a0b\u5355\u72ec\u5212\u5206\u4e00\u70b9\u7a7a\u95f4\u3002<\/p>\n

4\u3001(\u540c\u4e00\u8fdb\u7a0b\u4e2d\u7684)\u7ebf\u7a0b\u5728\u5171\u4eab\u5185\u5b58\u7a7a\u95f4\u4e2d\u8fd0\u884c\uff0c\u800c\u8fdb\u7a0b\u5728\u4e0d\u540c\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\u8fd0\u884c\u3002<\/p>\n

5\u3001\u7ebf\u7a0b\u53ef\u4ee5\u4f7f\u7528wait()\uff0cnotify()\uff0cnotifyAll()\u7b49\u65b9\u6cd5\u76f4\u63a5\u4e0e\u5176\u4ed6\u7ebf\u7a0b(\u540c\u4e00\u8fdb\u7a0b)\u901a\u4fe1;\u800c\uff0c\u8fdb\u7a0b\u9700\u8981\u4f7f\u7528\u201c\u8fdb\u7a0b\u95f4\u901a\u4fe1\u201d(IPC)\u6765\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5176\u4ed6\u8fdb\u7a0b\u901a\u4fe1\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662f\u5173\u4e8e\u5927\u6570\u636e\u5f00\u53d1\u57fa\u7840\u4e4bJAVA\u7ebf\u7a0b\u8fdb\u7a0b\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5b66\u4ee5\u81f4\u7528\u662f\u5927\u6570\u636e\u91cc\u9762\u6700\u597d\u7684\u5b66\u4e60\u65b9\u5f0f\uff0c\u80fd\u8ba9\u4f60\u5feb\u901f\u5728\u884c\u4e1a\u4e2d\u5360\u9886\u4e00\u5e2d\u4e4b\u5730\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728JAVA\u4e2d\u51e0\u4e4e\u4efb\u4f55\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u652f\u6301\u8fd0\u884c\u591a\u4e2a\u4efb\u52a1\uff0c\u901a\u5e38\u4e00\u4e2a\u4efb\u52a1\u5c31\u662f\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u800c\u4e00\u4e2a\u7a0b\u5e8f\u5c31\u662f\u4e00\u4e2a\u8fdb\u7a0b\u3002\u5f53\u4e00\u4e2a\u8fdb\u7a0b […]<\/p>\n","protected":false},"author":1329,"featured_media":216131,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-216129","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=216129"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216129\/revisions"}],"predecessor-version":[{"id":216133,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216129\/revisions\/216133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/216131"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=216129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=216129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=216129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}