{"id":207,"date":"2015-04-13T11:41:37","date_gmt":"2015-04-13T03:41:37","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=207"},"modified":"2026-08-18T12:09:29","modified_gmt":"2026-08-18T04:09:29","slug":"java%e7%ba%bf%e7%a8%8b%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=207","title":{"rendered":"Java\u7ebf\u7a0b\u6a21\u578b"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">Java \u8fd0\u884c\u65f6\u5728\u5f88\u591a\u65b9\u9762\u4f9d\u8d56\u7ebf\u7a0b\uff0c\u7c7b\u5e93\u8bbe\u8ba1\u4e5f\u6309\u591a\u7ebf\u7a0b\u6765\u8003\u8651\u3002\u5b9e\u9645\u4e0a Java \u7528\u7ebf\u7a0b\u8ba9\u6574\u4e2a\u73af\u5883\u5f02\u6b65\uff0c\u907f\u514d CPU \u7a7a\u8f6c\u6d6a\u8d39\u3002<\/p>\n<p><!--more--><\/p>\n<p style=\"margin: 1em 0px;\">\u5bf9\u7167\u5355\u7ebf\u7a0b\u66f4\u5bb9\u6613\u770b\u6e05\u4f18\u52bf\u3002\u5355\u7ebf\u7a0b\u5e38\u7528\u8f6e\u8be2\u4e8b\u4ef6\u5faa\u73af\uff1a\u4e00\u6761\u7ebf\u7a0b\u5728\u65e0\u9650\u5faa\u73af\u91cc\u8be2\u95ee\u4e8b\u4ef6\u5e8f\u5217\uff0c\u51b3\u5b9a\u4e0b\u4e00\u6b65\u3002\u4e00\u65e6\u67d0\u5904\u7406\u7a0b\u5e8f\u5360\u4f4f\uff0c\u522b\u7684\u4e8b\u4ef6\u53ea\u80fd\u7b49\u3002\u7ebf\u7a0b\u56e0\u4e3a\u7b49\u8d44\u6e90\u963b\u585e\u65f6\uff0c<strong style=\"color: #4870ac;\">\u6574\u4e2a\u7a0b\u5e8f\u505c\u4f4f<\/strong>\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u591a\u7ebf\u7a0b\u53d6\u6d88\u8f6e\u8be2<\/h2>\n<p style=\"margin: 1em 0px;\">Java \u591a\u7ebf\u7a0b\u7684\u4f18\u70b9\u662f\u53d6\u6d88\u4e3b\u5faa\u73af \/ \u8f6e\u8be2\u3002\u4e00\u6761\u7ebf\u7a0b\u53ef\u4ee5\u6682\u505c\u800c\u4e0d\u62d6\u57ae\u5176\u4ed6\u90e8\u5206\uff1a\u7b49\u7f51\u7edc\u3001\u7b49\u7528\u6237\u8f93\u5165\u7684\u7a7a\u95f2\u53ef\u4ee5\u7ed9\u522b\u4eba\u7528\u3002\u52a8\u753b\u5faa\u73af\u53ef\u4ee5\u6bcf\u5e27\u95f4\u9699\u7761\u4e00\u79d2\uff0c\u800c\u4e0d\u6682\u505c\u6574\u4e2a\u7cfb\u7edf\u3002\u51fa\u73b0\u963b\u585e\u65f6\uff0c\u53ea\u6302\u8d77\u90a3\u4e00\u6761\u7ebf\u7a0b\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u7ebf\u7a0b\u7684\u51e0\u79cd\u72b6\u6001<\/h2>\n<p style=\"margin: 1em 0px;\">\u7ebf\u7a0b\u53ef\u4ee5\u6b63\u5728\u8fd0\u884c\uff08running\uff09\uff0c\u53ea\u8981\u62ff\u5230 CPU \u5c31\u80fd\u8dd1\u3002\u8fd0\u884c\u4e2d\u7684\u7ebf\u7a0b\u53ef\u4ee5\u88ab\u6302\u8d77\uff08suspend\uff09\u4e34\u65f6\u4e2d\u65ad\uff0c\u4e4b\u540e\u518d\u6062\u590d\uff08resume\uff09\u4ece\u505c\u4e0b\u7684\u5730\u65b9\u7ee7\u7eed\u3002\u7b49\u8d44\u6e90\u65f6\u4f1a\u88ab\u963b\u585e\uff08block\uff09\u3002\u4efb\u4f55\u65f6\u5019\u90fd\u53ef\u4ee5\u7ec8\u6b62\uff08terminate\uff09\uff1b\u4e00\u65e6\u7ec8\u6b62\u5c31\u4e0d\u80fd\u518d\u6062\u590d\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3929523.jpg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-679\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3929523.jpg\" alt=\"3929523\" width=\"531\" height=\"256\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3929523.jpg 581w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3929523-528x254.jpg 528w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3852520.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-680\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2015\/04\/3852520.png\" alt=\"3852520\" width=\"527\" height=\"375\" \/><\/a><\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u72b6\u6001<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">running<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u83b7\u5f97 CPU \u65f6\u95f4\u5373\u53ef\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">suspend \/ resume<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e34\u65f6\u4e2d\u65ad\uff0c\u518d\u4ece\u505c\u4e0b\u5904\u7ee7\u7eed\uff08\u73b0\u4ee3 API \u5df2\u4e0d\u63a8\u8350\u76f4\u63a5 suspend\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">block<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7b49\u5f85\u8d44\u6e90\u65f6\u6302\u8d77\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">terminate<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7acb\u5373\u4e2d\u65ad\uff0c\u4e0d\u80fd\u6062\u590d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u4f18\u5148\u7ea7\u4e0e\u4e0a\u4e0b\u6587\u8f6c\u6362<\/h2>\n<p style=\"margin: 1em 0px;\">Java \u7ed9\u6bcf\u4e2a\u7ebf\u7a0b\u4e00\u4e2a\u6574\u578b\u4f18\u5148\u7ea7\uff0c\u7528\u6765\u51b3\u5b9a\u4f55\u65f6\u4ece\u4e00\u6761\u8fd0\u884c\u4e2d\u7684\u7ebf\u7a0b\u5207\u5230\u53e6\u4e00\u6761\uff0c\u8fd9\u53eb\u4e0a\u4e0b\u6587\u8f6c\u6362\uff08context switch\uff09\u3002\u5355\u72ec\u4e00\u6761\u7ebf\u7a0b\u65f6\uff0c\u4f18\u5148\u7ea7\u9ad8\u5e76\u4e0d\u7b49\u4e8e\u8dd1\u5f97\u66f4\u5feb\u3002<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u7ebf\u7a0b\u53ef\u4ee5\u4e3b\u52a8\u653e\u5f03\u63a7\u5236\uff08IO\u3001sleep\u3001\u963b\u585e\u3001yield\uff09\u3002\u6b64\u65f6\u5c31\u7eea\u961f\u5217\u91cc\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u83b7\u5f97 CPU\u3002<\/section>\n<\/li>\n<li>\n<section>\u9ad8\u4f18\u5148\u7ea7\u7ebf\u7a0b\u53ef\u4ee5\u62a2\u5360\uff1a\u4f4e\u4f18\u5148\u7ea7\u5373\u4f7f\u4e0d\u8ba9\uff0c\u4e5f\u4f1a\u88ab\u5148\u5360\u3002\u8fd9\u53eb\u6709\u4f18\u5148\u6743\u7684\u591a\u4efb\u52a1\u3002<\/section>\n<\/li>\n<li>\n<section>\u540c\u4f18\u5148\u7ea7\u65f6\uff0cWindows \u4e00\u7c7b\u7cfb\u7edf\u5e38\u6309\u65f6\u95f4\u7247\u8f6e\u8f6c\uff1bSolaris 2.x \u4e00\u7c7b\u5219\u4f9d\u8d56\u7ebf\u7a0b\u4e3b\u52a8\u653e\u5f03\uff0c\u5426\u5219\u5bf9\u7b49\u7ebf\u7a0b\u53ef\u80fd\u8dd1\u4e0d\u5230\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u8b66\u544a\uff1a\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0b\uff0c\u7b49\u4f18\u5148\u7ea7\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u8f6c\u6362\u884c\u4e3a\u53ef\u80fd\u4e0d\u4e00\u6837\uff0c\u636e\u6b64\u5199\u903b\u8f91\u5bb9\u6613\u51fa\u9519\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001\u540c\u6b65\u3001\u6d88\u606f\u4e0e Thread \/ Runnable<\/h2>\n<p style=\"margin: 1em 0px;\">\u591a\u7ebf\u7a0b\u5f15\u5165\u5f02\u6b65\u884c\u4e3a\uff0c\u5171\u4eab\u94fe\u8868\u8fd9\u7c7b\u7ed3\u6784\u65f6\u5fc5\u987b\u9632\u6b62\u4e00\u4e2a\u7ebf\u7a0b\u5728\u5199\u3001\u53e6\u4e00\u4e2a\u5728\u8bfb\u3002Java \u5728\u7ba1\u7a0b\uff08monitor\uff0cC.A.R. Hoare \u63d0\u51fa\uff09\u6a21\u578b\u4e0a\u63d0\u4f9b\u8bed\u8a00\u7ea7\u540c\u6b65\uff1a\u6ca1\u6709\u5355\u72ec\u7684 Monitor \u7c7b\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u9690\u5f0f\u7ba1\u7a0b\uff1b\u8c03\u7528\u540c\u6b65\u65b9\u6cd5\u65f6\u81ea\u52a8\u8fdb\u5165\u3002\u4e00\u6761\u7ebf\u7a0b\u5f85\u5728\u67d0\u5bf9\u8c61\u7684\u540c\u6b65\u65b9\u6cd5\u91cc\u65f6\uff0c\u5176\u4ed6\u7ebf\u7a0b\u4e0d\u80fd\u518d\u8c03\u8be5\u5bf9\u8c61\u7684\u540c\u6b65\u65b9\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u7ebf\u7a0b\u62c6\u5f00\u4e4b\u540e\u8981\u5b9a\u4e49\u8054\u7cfb\u3002\u522b\u7684\u8bed\u8a00\u5e38\u9760\u64cd\u4f5c\u7cfb\u7edf\u505a\u7ebf\u7a0b\u95f4\u901a\u4fe1\uff0c\u6210\u672c\u9ad8\u3002Java \u901a\u8fc7\u5bf9\u8c61\u4e0a\u9884\u5b9a\u7684\u65b9\u6cd5\uff0c\u8ba9\u4e00\u6761\u7ebf\u7a0b\u8fdb\u5165\u540c\u6b65\u65b9\u6cd5\u540e wait\uff0c\u76f4\u5230\u53e6\u4e00\u6761\u660e\u786e notify \u5b83\u51fa\u6765\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u591a\u7ebf\u7a0b\u5efa\u7acb\u5728 Thread \u7c7b\u53ca\u5176\u4f19\u4f34\u63a5\u53e3 Runnable \u4e0a\u3002Thread \u5c01\u88c5\u7ebf\u7a0b\u7684\u6267\u884c\uff1b\u4f60\u4e0d\u80fd\u76f4\u63a5\u5f15\u7528\u8fd0\u884c\u4e2d\u7ebf\u7a0b\u7684\u72b6\u6001\uff0c\u53ea\u80fd\u901a\u8fc7\u4ee3\u7406\uff08Thread \u5b9e\u4f8b\uff09\u64cd\u4f5c\u3002\u8981\u521b\u5efa\u65b0\u7ebf\u7a0b\uff0c\u7a0b\u5e8f\u5fc5\u987b\u6269\u5c55 Thread \u6216\u5b9e\u73b0 Runnable\u3002\u5230\u76ee\u524d\u4e3a\u6b62\u7684\u4f8b\u5b50\u90fd\u662f\u5355\u7ebf\u7a0b\uff1b\u540e\u9762\u4ece\u6240\u6709 Java \u7a0b\u5e8f\u90fd\u6709\u7684\u90a3\u6761\u7ebf\u2014\u2014\u4e3b\u7ebf\u7a0b\u2014\u2014\u5f00\u59cb\u8bb2\u5982\u4f55\u521b\u5efa\u548c\u7ba1\u7406\u3002<\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u591a\u7ebf\u7a0b\u7528\u6682\u505c\u6362\u8f6e\u8be2\uff0c\u963b\u585e\u53ea\u505c\u4e00\u6761\uff1b\u4f18\u5148\u7ea7\u51b3\u5b9a\u4f55\u65f6\u5207\u6362\uff0c\u5171\u4eab\u6570\u636e\u9760\u5bf9\u8c61\u9690\u5f0f\u7ba1\u7a0b\uff0c\u65b0\u5efa\u7ebf\u7a0b\u8981\u4e48 extend Thread\uff0c\u8981\u4e48 implement Runnable\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Java \u8fd0\u884c\u65f6\u5728\u5f88\u591a\u65b9\u9762\u4f9d\u8d56\u7ebf\u7a0b\uff0c\u7c7b\u5e93\u8bbe\u8ba1\u4e5f\u6309\u591a\u7ebf\u7a0b\u6765\u8003\u8651\u3002\u5b9e\u9645\u4e0a Java \u7528\u7ebf\u7a0b\u8ba9\u6574\u4e2a\u73af\u5883\u5f02\u6b65\uff0c\u907f\u514d C [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[178],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/207"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=207"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":681,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/207\/revisions\/681"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}