{"id":34288,"date":"2025-04-29T09:14:52","date_gmt":"2025-04-29T01:14:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/34288.html"},"modified":"2025-04-29T09:14:52","modified_gmt":"2025-04-29T01:14:52","slug":"%e5%ae%9a%e6%97%b6%e5%99%a8%e7%9a%84%e6%ba%90%e7%a0%81%e4%bb%8b%e7%bb%8d%e4%b8%8e%e7%ae%80%e5%8d%95%e5%ae%9e%e7%8e%b0-%e5%a4%9a%e7%ba%bf%e7%a8%8b%e7%bc%96%e7%a8%8b%e7%ae%80%e5%8d%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/34288.html","title":{"rendered":"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)]"},"content":{"rendered":"<h2 id=\"%C2%A0%C2%A0\" style=\"background-color:transparent\">\u00a0\u00a0<\/h2>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E5%89%8D%E8%A8%80-toc\" style=\"margin-left:0px\">\u524d\u8a00<\/p>\n<p id=\"%E4%BB%80%E4%B9%88%E6%98%AF%E5%AE%9A%E6%97%B6%E5%99%A8-toc\" style=\"margin-left:0px\">\u4ec0\u4e48\u662f\u5b9a\u65f6\u5668<\/p>\n<p id=\"JAVA%E6%A0%87%E5%87%86%E5%BA%93%E4%B8%AD%E7%9A%84%E5%AE%9A%E6%97%B6%E5%99%A8-toc\" style=\"margin-left:0px\">JAVA\u6807\u51c6\u5e93\u4e2d\u7684\u5b9a\u65f6\u5668<\/p>\n<p id=\"%E8%80%8C%E5%85%B3%E4%BA%8Esched%E6%96%B9%E6%B3%95%2C%E8%AF%B7%E7%9C%8B%E6%BA%90%E7%A0%81%3A-toc\" style=\"margin-left:40px\">\u800c\u5173\u4e8esched\u65b9\u6cd5,\u8bf7\u770b\u6e90\u7801:<\/p>\n<p id=\"%C2%A0%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E4%BB%AC%E8%83%BD%E7%9F%A5%E9%81%93%22notify()%20%E5%94%A4%E9%86%92%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%20TimerThread%22%3F-toc\" style=\"margin-left:40px\">\u00a0\u4e3a\u4ec0\u4e48\u6211\u4eec\u80fd\u77e5\u9053&#034;notify() \u5524\u9192\u540e\u53f0\u7ebf\u7a0b TimerThread&#034;?<\/p>\n<p id=\"TimerThread%20%E5%85%B3%E9%94%AE%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:40px\">TimerThread \u5173\u952e\u903b\u8f91<\/p>\n<p id=\"%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%9A%E5%8A%A0%E9%94%81%20queue%EF%BC%8C%E7%9C%8B%E6%9C%89%E6%B2%A1%E6%9C%89%E4%BB%BB%E5%8A%A1-toc\" style=\"margin-left:80px\">\u7b2c\u4e00\u6b65&#xff1a;\u52a0\u9501 queue&#xff0c;\u770b\u6709\u6ca1\u6709\u4efb\u52a1<\/p>\n<p id=\"%E7%AC%AC%E4%BA%8C%E6%AD%A5%EF%BC%9A%E5%8F%96%E5%87%BA%E6%9C%80%E8%BF%91%E8%A6%81%E6%89%A7%E8%A1%8C%E7%9A%84%E4%BB%BB%E5%8A%A1%C2%A0-toc\" style=\"margin-left:80px\">\u7b2c\u4e8c\u6b65&#xff1a;\u53d6\u51fa\u6700\u8fd1\u8981\u6267\u884c\u7684\u4efb\u52a1\u00a0<\/p>\n<p id=\"%E7%AC%AC%E4%B8%89%E6%AD%A5%EF%BC%9A%E7%9C%8B%E4%BB%BB%E5%8A%A1%E8%83%BD%E4%B8%8D%E8%83%BD%E6%89%A7%E8%A1%8C%C2%A0-toc\" style=\"margin-left:80px\">\u7b2c\u4e09\u6b65&#xff1a;\u770b\u4efb\u52a1\u80fd\u4e0d\u80fd\u6267\u884c\u00a0<\/p>\n<p id=\"%C2%A0%E7%AC%AC%E5%9B%9B%E6%AD%A5%3A%20%E5%88%A4%E6%96%AD%E4%BB%BB%E5%8A%A1%E6%98%AF%E5%90%A6%E6%98%AF%E5%91%A8%E6%9C%9F%E6%80%A7%E7%9A%84-toc\" style=\"margin-left:80px\">\u00a0\u7b2c\u56db\u6b65: \u5224\u65ad\u4efb\u52a1\u662f\u5426\u662f\u5468\u671f\u6027\u7684<\/p>\n<p id=\"%C2%A0%E7%AC%AC%E5%85%AD%E6%AD%A5%3A%20%E6%89%A7%E8%A1%8C-toc\" style=\"margin-left:80px\">\u00a0\u7b2c\u4e94\u6b65: \u6267\u884c<\/p>\n<p id=\"%E4%B8%BE%E4%B8%AA%E4%BE%8B%E5%AD%90%2C%E8%AF%B7%E7%9C%8B%E4%BB%A3%E7%A0%81%3A-toc\" style=\"margin-left:40px\">\u4e3e\u4e2a\u4f8b\u5b50,\u8bf7\u770b\u4ee3\u7801:<\/p>\n<p id=\"%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E5%AE%9A%E6%97%B6%E5%99%A8-toc\" style=\"margin-left:0px\">\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u5b9a\u65f6\u5668<\/p>\n<p id=\"%E7%BB%93%E5%B0%BE%C2%A0-toc\" style=\"margin-left:0px\">\u7ed3\u5c3e\u00a0<\/p>\n<\/p>\n<h2 id=\"%E5%89%8D%E8%A8%80\" style=\"background-color:transparent\">\u524d\u8a00<\/h2>\n<p>\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d&#xff0c;\u591a\u7ebf\u7a0b\u7f16\u7a0b\u80fd\u529b\u5df2\u7ecf\u6210\u4e3a\u7a0b\u5e8f\u5458\u5fc5\u987b\u638c\u63e1\u7684\u4e00\u9879\u6838\u5fc3\u6280\u80fd\u3002\u968f\u7740\u8ba1\u7b97\u673a\u786c\u4ef6\u7684\u4e0d\u65ad\u5347\u7ea7&#xff0c;\u5355\u6838CPU\u65e9\u5df2\u65e0\u6cd5\u6ee1\u8db3\u590d\u6742\u5e94\u7528\u7684\u6027\u80fd\u9700\u6c42&#xff0c;\u591a\u6838\u5e76\u884c\u8fd0\u7b97\u5df2\u6210\u4e3a\u4e3b\u6d41\u3002\u800c\u591a\u7ebf\u7a0b\u6b63\u662f\u5b9e\u73b0\u8d44\u6e90\u6700\u5927\u5316\u5229\u7528\u3001\u4efb\u52a1\u9ad8\u6548\u5e76\u884c\u6267\u884c\u7684\u57fa\u7840\u624b\u6bb5\u3002<\/p>\n<p>\u800c\u672c\u535a\u5ba2\u662f\u7b14\u8005\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u7b2c\u4e94\u7bc7\u535a\u5ba2! \u524d\u9762\u56db\u7bc7\u90fd\u5728\u4e0b\u9762\u7684URL\u4e2d,\u5e0c\u671b\u80fd\u5f97\u5230\u5927\u4f6c\u4eec\u7684\u9605\u8bfb\u548c\u6307\u70b9!!!<\/p>\n<p>\u591a\u7ebf\u7a0b\u7f16\u7a0b_callJJ\u7684\u535a\u5ba2-CSDN\u535a\u5ba2<\/p>\n<p>\u672c\u671f\u6211\u4eec\u4ecb\u7ecd\u7684\u662f\u5b9a\u65f6\u5668,\u7136\u540e\u7ffb\u770b\u5e76\u4e14\u4ecb\u7ecd\u5b83\u7684\u6e90\u7801,\u4ee5\u53ca\u5982\u4f55\u7b80\u5355\u7684\u5b9e\u73b0\u4e00\u4e2a\u5b9a\u65f6\u5668,\u5e76\u901a\u8fc7\u5b83\u7684\u7b80\u5355\u5b9e\u73b0\u63d0\u9ad8\u6211\u4eec\u5bf9\u4e8e\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u7406\u89e3,\u5e9f\u8bdd\u4e0d\u591a\u8bf4,\u8ba9\u6211\u4eec\u6b63\u5f0f\u5f00\u59cb\u535a\u5ba2\u5185\u5bb9!<\/p>\n<h2 id=\"%E4%BB%80%E4%B9%88%E6%98%AF%E5%AE%9A%E6%97%B6%E5%99%A8\">\u4ec0\u4e48\u662f\u5b9a\u65f6\u5668<\/h2>\n<p>\u5728\u5b9e\u73b0\u5b9a\u65f6\u5668\u4e4b\u524d,\u6211\u4eec\u8fd8\u662f \u8981\u5148\u4ecb\u7ecd\u4e00\u4e0b\u4ec0\u4e48\u662f\u5b9a\u65f6\u5668<\/p>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u5b9a\u65f6\u5668&#xff08;Timer&#xff09;\u5c31\u662f\u4e00\u79cd\u5141\u8bb8\u7a0b\u5e8f\u5728\u6307\u5b9a\u65f6\u95f4\u540e\u6216\u8005\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5468\u671f\u6027\u5730\u6267\u884c\u67d0\u4e2a\u4efb\u52a1\u7684\u673a\u5236\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u5ef6\u8fdf\u6267\u884c\u6216\u8005\u5b9a\u65f6\u91cd\u590d\u6267\u884c\u64cd\u4f5c\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d,\u5b83\u7684\u7528\u5904\u4e5f\u5f88\u5e7f\u6cdb,\u4f8b\u5982:<\/p>\n<ul>\n<li>\n<p>\u754c\u9762\u52a8\u753b\u7684\u5237\u65b0<\/p>\n<\/li>\n<li>\n<p>\u6e38\u620f\u4e2d\u5b9a\u65f6\u751f\u6210\u602a\u7269<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u7aef\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u6e05\u7406\u7f13\u5b58<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u65f6\u53d1\u9001\u5fc3\u8df3\u5305\u68c0\u6d4b\u8fde\u63a5\u662f\u5426\u5b58\u6d3b<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u65f6\u5907\u4efd\u6587\u4ef6\u7cfb\u7edf\u6570\u636e\u7b49<\/p>\n<\/li>\n<\/ul>\n<p>\u00a0\u4e3e\u4e2a\u4f8b\u5b50,\u4ed6\u5c31\u597d\u50cf\u662f\u751f\u6d3b\u4e2d\u7684\u95f9\u949f,\u8bbe\u5b9a\u8fbe\u5230\u4e00\u4e2a\u65f6\u95f4\u4ee5\u540e,\u5c31\u6267\u884c\u67d0\u4e9b\u6307\u5b9a\u597d\u7684\u4ee3\u7801!<\/p>\n<h2 id=\"JAVA%E6%A0%87%E5%87%86%E5%BA%93%E4%B8%AD%E7%9A%84%E5%AE%9A%E6%97%B6%E5%99%A8\" style=\"background-color:transparent\">JAVA\u6807\u51c6\u5e93\u4e2d\u7684\u5b9a\u65f6\u5668<\/h2>\n<p>Java \u6807\u51c6\u5e93\u91cc\u6700\u65e9\u63d0\u4f9b\u7684\u5b9a\u65f6\u5668\u5c31\u662f java.util.Timer&#xff0c;\u642d\u914d java.util.TimerTask \u4f7f\u7528\u3002\u5b83\u7684\u6838\u5fc3\u8bbe\u8ba1\u601d\u8def\u975e\u5e38\u76f4\u63a5&#xff1a;<\/p>\n<p>1.Timer \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5355\u7ebf\u7a0b\u7684\u4efb\u52a1\u8c03\u5ea6\u5668&#xff0c;\u5b83\u5185\u90e8\u7ef4\u62a4\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u4e0d\u65ad\u5730\u68c0\u67e5\u4efb\u52a1\u961f\u5217\u4e2d\u4e0b\u4e00\u4e2a\u8981\u6267\u884c\u7684\u4efb\u52a1\u65f6\u95f4\u3002\u5b83\u7684\u6838\u5fc3\u65b9\u6cd5\u4e3a schedule<\/p>\n<p>\u5b83\u5305\u542b\u4e24\u4e2a\u53c2\u6570,\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u6307\u5b9a\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\u4ee3\u7801,\u7b2c\u4e8c\u4e2a\u6307\u4ee4\u662f\u5ef6\u957f\u591a\u5c11 ms<\/p>\n<p>2.\u00a0TimerTask \u5219\u662f\u4f60\u8981\u6267\u884c\u7684\u5177\u4f53\u4efb\u52a1&#xff0c;\u9700\u8981\u7ee7\u627f\u8fd9\u4e2a\u62bd\u8c61\u7c7b\u5e76\u91cd\u5199 run() \u65b9\u6cd5\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u7ffb\u770b\u5b83\u4eec\u7684\u6e90\u7801\u7565\u77e5\u4e00\u4e8c: <\/p>\n<p>    public void schedule(TimerTask task, long delay) {<br \/>\n        if (delay &lt; 0)<br \/>\n            throw new IllegalArgumentException(&#034;Negative delay.&#034;);<br \/>\n        sched(task, System.currentTimeMillis()&#043;delay, 0);<br \/>\n    } <\/p>\n<p>\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u8c03\u7528 Timer.schedule(TimerTask task, long delay)&#xff0c;\u8868\u793a\u5b89\u6392\u4e00\u4e2a\u4efb\u52a1\u5728\u6307\u5b9a\u5ef6\u8fdf\u540e\u6267\u884c\u3002 \u8fd9\u4e00\u8c03\u7528\u5e76\u4e0d\u4f1a\u76f4\u63a5\u6267\u884c task.run()&#xff0c;\u800c\u662f\u5185\u90e8\u8c03\u7528 sched() \u65b9\u6cd5&#xff0c;\u5c06\u4efb\u52a1\u6dfb\u52a0\u5230 Timer \u7684\u4efb\u52a1\u961f\u5217\u4e2d\u3002\u00a0<\/p>\n<p>\u5e76\u4e14\u53ef\u4ee5\u770b\u5230,schedule\u65b9\u6cd5\u9700\u8981\u4e00\u4e2a\u00a0\u00a0TimerTask\u5bf9\u8c61.<\/p>\n<p>\u800c\u6211\u4eec\u7684\u00a0\u00a0TimerTask\u00a0 \u662f\u4e00\u4e2a\u7ee7\u627f\u4e86\u00a0 Runnable \u63a5\u53e3\u7684 \u62bd\u8c61\u7c7b,\u6240\u4ee5\u4e3a\u4e86\u5b9e\u4f8b\u5316TimerTask,\u9700\u8981\u91cd\u5199 run()\u65b9\u6cd5\u00a0<\/p>\n<p>public abstract class TimerTask implements Runnable  <\/p>\n<p>\u00a0<\/p>\n<h3 id=\"%E8%80%8C%E5%85%B3%E4%BA%8Esched%E6%96%B9%E6%B3%95%2C%E8%AF%B7%E7%9C%8B%E6%BA%90%E7%A0%81%3A\" style=\"background-color:transparent\">\u800c\u5173\u4e8esched\u65b9\u6cd5,\u8bf7\u770b\u6e90\u7801: <\/h3>\n<p>   private void sched(TimerTask task, long time, long period) {<br \/>\n        if (time &lt; 0)<br \/>\n            throw new IllegalArgumentException(&#034;Illegal execution time.&#034;);<\/p>\n<p>        \/\/ Constrain value of period sufficiently to prevent numeric<br \/>\n        \/\/ overflow while still being effectively infinitely large.<br \/>\n        if (Math.abs(period) &gt; (Long.MAX_VALUE &gt;&gt; 1))<br \/>\n            period &gt;&gt;&#061; 1;<\/p>\n<p>        synchronized(queue) {<br \/>\n            if (!thread.newTasksMayBeScheduled)<br \/>\n                throw new IllegalStateException(&#034;Timer already cancelled.&#034;);<\/p>\n<p>            synchronized(task.lock) {<br \/>\n                if (task.state !&#061; TimerTask.VIRGIN)<br \/>\n                    throw new IllegalStateException(<br \/>\n                        &#034;Task already scheduled or cancelled&#034;);<br \/>\n                task.nextExecutionTime &#061; time;<br \/>\n                task.period &#061; period;<br \/>\n                task.state &#061; TimerTask.SCHEDULED;<br \/>\n            }<\/p>\n<p>            queue.add(task);<br \/>\n            if (queue.getMin() &#061;&#061; task)<br \/>\n                queue.notify();<br \/>\n        }<br \/>\n    } <\/p>\n<p>sched() \u65b9\u6cd5\u8d1f\u8d23&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5148\u8ba1\u7b97\u51fa\u4efb\u52a1\u7684\u4e0b\u6b21\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u7136\u540e\u5c06 TimerTask \u63d2\u5165\u5230 PriorityQueue&#xff08;\u4f18\u5148\u961f\u5217&#xff09;\u4e2d&#xff0c;\u6309\u65f6\u95f4\u6392\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e\u8c03\u7528 notify() \u5524\u9192\u540e\u53f0\u7ebf\u7a0b TimerThread&#xff0c;\u8ba9\u5b83\u77e5\u9053\u6709\u65b0\u4efb\u52a1\u8981\u5904\u7406\u3002<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"%C2%A0%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E4%BB%AC%E8%83%BD%E7%9F%A5%E9%81%93%22notify()%20%E5%94%A4%E9%86%92%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B%20TimerThread%22%3F\" style=\"background-color:transparent\">\u00a0\u4e3a\u4ec0\u4e48\u6211\u4eec\u80fd\u77e5\u9053&#034;notify() \u5524\u9192\u540e\u53f0\u7ebf\u7a0b TimerThread&#034;?<\/h3>\n<p>\u8bf7\u770b\u00a0\u00a0 TimerThread \u4e2d\u7684\u4ee3\u7801<\/p>\n<p>    private void mainLoop() {<br \/>\n        while (true) {<br \/>\n            try {<br \/>\n                TimerTask task;<br \/>\n                boolean taskFired;<br \/>\n                synchronized(queue) {<br \/>\n                    \/\/ Wait for queue to become non-empty<br \/>\n                    while (queue.isEmpty() &amp;&amp; newTasksMayBeScheduled)<br \/>\n                        queue.wait();<br \/>\n                    if (queue.isEmpty())<br \/>\n                        break; \/\/ Queue is empty and will forever remain; die<\/p>\n<p>                    \/\/ Queue nonempty; look at first evt and do the right thing<br \/>\n                    long currentTime, executionTime;<br \/>\n                    task &#061; queue.getMin();<br \/>\n                    synchronized(task.lock) {<br \/>\n                        if (task.state &#061;&#061; TimerTask.CANCELLED) {<br \/>\n                            queue.removeMin();<br \/>\n                            continue;  \/\/ No action required, poll queue again<br \/>\n                        }<br \/>\n                        currentTime &#061; System.currentTimeMillis();<br \/>\n                        executionTime &#061; task.nextExecutionTime;<br \/>\n                        if (taskFired &#061; (executionTime&lt;&#061;currentTime)) {<br \/>\n                            if (task.period &#061;&#061; 0) { \/\/ Non-repeating, remove<br \/>\n                                queue.removeMin();<br \/>\n                                task.state &#061; TimerTask.EXECUTED;<br \/>\n                            } else { \/\/ Repeating task, reschedule<br \/>\n                                queue.rescheduleMin(<br \/>\n                                  task.period&lt;0 ? currentTime   &#8211; task.period<br \/>\n                                                : executionTime &#043; task.period);<br \/>\n                            }<br \/>\n                        }<br \/>\n                    }<br \/>\n                    if (!taskFired) \/\/ Task hasn&#039;t yet fired; wait<br \/>\n                        queue.wait(executionTime &#8211; currentTime);<br \/>\n                }<br \/>\n                if (taskFired)  \/\/ Task fired; run it, holding no locks<br \/>\n                    task.run();<br \/>\n            } catch(InterruptedException e) {<br \/>\n            }<br \/>\n        }<br \/>\n    } <\/p>\n<p>\u4f60\u5bf9\u6bd4\u4e00\u4e0b\u00a0\u00a0sched() \u65b9\u6cd5 \u7684\u4ee3\u7801\u5c31\u4f1a\u53d1\u73b0,\u5b83\u4eec\u6709\u540c\u4e00\u4e2a\u52a0\u9501\u5bf9\u8c61\u2014\u2014 queue.<\/p>\n<p>\u5982\u679cqueue\u662f\u7a7a\u7684&#xff08;\u5373\u5f53\u524d\u6ca1\u6709\u5b9a\u65f6\u4efb\u52a1&#xff09;&#xff0c;\u5e76\u4e14newTasksMayBeScheduled &#061;&#061; true&#xff08;\u5373\u5141\u8bb8\u7ee7\u7eed\u6dfb\u52a0\u65b0\u4efb\u52a1&#xff09;&#xff0c;\u90a3\u4e48\u5f53\u524d TimerThread \u5c31\u5728 queue \u4e0a\u8c03\u7528 wait()&#xff0c;\u6302\u8d77\u81ea\u5df1&#xff0c;\u7b49\u5f85\u65b0\u7684\u4efb\u52a1\u5230\u6765\u3002<\/p>\n<p>\u8fd9\u4e0e\u524d\u9762\u7684 notify()\u65b9\u6cd5\u9065\u76f8\u547c\u5e94<\/p>\n<p>\u4ee5\u4e0b\u662f\u5b8c\u5584\u6d41\u7a0b:<\/p>\n<p> main\u7ebf\u7a0b&#xff1a;<br \/>\n    Timer.schedule(task, delay)<br \/>\n        -&gt; sched(task, \u65f6\u95f4, \u5468\u671f)<br \/>\n            -&gt; queue.add(task)<br \/>\n            -&gt; queue.notify()<\/p>\n<p>\u540e\u53f0\u7ebf\u7a0b&#xff08;TimerThread&#xff09;&#xff1a;<br \/>\n    run() -&gt; mainLoop()<br \/>\n        -&gt; \u7b49\u5f85\u4efb\u52a1<br \/>\n        -&gt; \u5230\u4e86\u6267\u884c\u65f6\u95f4<br \/>\n        -&gt; \u8c03\u7528 task.run()<\/p>\n<h3 id=\"TimerThread%20%E5%85%B3%E9%94%AE%E9%80%BB%E8%BE%91\" style=\"background-color:transparent\">TimerThread \u5173\u952e\u903b\u8f91<\/h3>\n<p>\u90a3\u4e48,\u00a0TimerThread \u5173\u952e\u903b\u8f91 \u662f\u4ec0\u4e48\u5462?\u5b83\u662f\u600e\u4e48\u4e00\u6b65\u4e00\u6b65\u7684\u6210\u529f\u8c03\u7528 run() \u7684\u5462?<\/p>\n<h4 id=\"%E7%AC%AC%E4%B8%80%E6%AD%A5%EF%BC%9A%E5%8A%A0%E9%94%81%20queue%EF%BC%8C%E7%9C%8B%E6%9C%89%E6%B2%A1%E6%9C%89%E4%BB%BB%E5%8A%A1\">\u7b2c\u4e00\u6b65&#xff1a;\u52a0\u9501 queue&#xff0c;\u770b\u6709\u6ca1\u6709\u4efb\u52a1<\/h4>\n<p>synchronized(queue) {<br \/>\n    while (queue.isEmpty() &amp;&amp; newTasksMayBeScheduled)<br \/>\n        queue.wait();<br \/>\n    if (queue.isEmpty())<br \/>\n        break;<br \/>\n}<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u6ca1\u6709\u4efb\u52a1&#xff0c;\u5c31 wait \u6302\u8d77\u7b49\u5f85\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u9192\u6765\u540e\u53d1\u73b0\u8fd8\u662f\u6ca1\u4efb\u52a1\u4e14\u4e0d\u5141\u8bb8\u52a0\u4e86&#xff0c;\u5c31 break \u9000\u51fa\u7ebf\u7a0b\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"%E7%AC%AC%E4%BA%8C%E6%AD%A5%EF%BC%9A%E5%8F%96%E5%87%BA%E6%9C%80%E8%BF%91%E8%A6%81%E6%89%A7%E8%A1%8C%E7%9A%84%E4%BB%BB%E5%8A%A1%C2%A0\">\u7b2c\u4e8c\u6b65&#xff1a;\u53d6\u51fa\u6700\u8fd1\u8981\u6267\u884c\u7684\u4efb\u52a1\u00a0<\/h4>\n<p>task &#061; queue.getMin();<\/p>\n<ul>\n<li>\n<p>getMin() \u53d6\u51fa\u6700\u65e9\u5e94\u8be5\u6267\u884c\u7684\u90a3\u4e2a\u4efb\u52a1&#xff08;\u4f18\u5148\u961f\u5217\u5c0f\u9876\u5806&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e5f\u5c31\u662f\u5f53\u524d\u6700\u7d27\u6025\u7684\u4efb\u52a1\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"%E7%AC%AC%E4%B8%89%E6%AD%A5%EF%BC%9A%E7%9C%8B%E4%BB%BB%E5%8A%A1%E8%83%BD%E4%B8%8D%E8%83%BD%E6%89%A7%E8%A1%8C%C2%A0\">\u7b2c\u4e09\u6b65&#xff1a;\u770b\u4efb\u52a1\u80fd\u4e0d\u80fd\u6267\u884c\u00a0<\/h4>\n<p>if (task.state &#061;&#061; TimerTask.CANCELLED) {<br \/>\n    queue.removeMin();<br \/>\n    continue;<br \/>\n}<\/p>\n<p>\u00a0\u5982\u679c\u53d1\u73b0\u4efb\u52a1\u88ab\u53d6\u6d88\u4e86&#xff0c;\u5c31\u4ece\u961f\u5217\u79fb\u9664&#xff0c;\u7ee7\u7eed\u5faa\u73af\u3002<\/p>\n<p>\u7136\u540e\u5f97\u5230\u76ee\u524d\u7684\u65f6\u95f4,\u5224\u65ad\u80fd\u5426\u6267\u884c<\/p>\n<p> currentTime &#061; System.currentTimeMillis();<br \/>\n  executionTime &#061; task.nextExecutionTime;<br \/>\n        if (taskFired &#061; (executionTime&lt;&#061;currentTime)) {<br \/>\n           if (task.period &#061;&#061; 0) { \/\/ Non-repeating, remove<br \/>\n            queue.removeMin();<br \/>\n     task.state &#061; TimerTask.EXECUTED;<br \/>\n       } else { \/\/ Repeating task, reschedule<br \/>\n         queue.rescheduleMin(<br \/>\n      task.period&lt;0 ? currentTime   &#8211; task.period<br \/>\n      : executionTime &#043; task.period);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8bbe\u7f6e \u6807\u5fd7\u4f4d taskFired<\/p>\n<p><span style=\"color:#fe2c24\">executionTime &lt;&#061; currentTime <\/span>\u5224\u65ad\u4efb\u52a1\u7684\u6267\u884c\u65f6\u95f4\u662f\u5426\u5df2\u7ecf\u5230\u8fbe\u5f53\u524d\u65f6\u95f4\u3002\u5982\u679c\u5230\u8fbe\u6267\u884c\u65f6\u95f4&#xff0c;taskFired \u88ab\u8bbe\u4e3a true&#xff0c;\u8868\u793a\u4efb\u52a1\u53ef\u4ee5\u6267\u884c\u3002\u5982\u679c\u6ca1\u6709\u5230\u8fbe\u6267\u884c\u65f6\u95f4&#xff0c;taskFired\u00a0\u4f1a\u88ab\u8bbe\u4e3afalse&#xff0c;\u8868\u793a\u4efb\u52a1\u4e0d\u80fd\u6267\u884c&#xff0c;\u5e94\u8be5\u7b49\u5f85\u3002<\/p>\n<h4 id=\"%C2%A0%E7%AC%AC%E5%9B%9B%E6%AD%A5%3A%20%E5%88%A4%E6%96%AD%E4%BB%BB%E5%8A%A1%E6%98%AF%E5%90%A6%E6%98%AF%E5%91%A8%E6%9C%9F%E6%80%A7%E7%9A%84\" style=\"background-color:transparent\">\u00a0\u7b2c\u56db\u6b65: \u5224\u65ad\u4efb\u52a1\u662f\u5426\u662f\u5468\u671f\u6027\u7684<\/h4>\n<p>\u00a0\u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u662f\u975e\u5468\u671f\u6027\u8d28\u7684<\/p>\n<p>if (task.period &#061;&#061; 0) { \/\/ Non-repeating, remove<br \/>\n    queue.removeMin();  \/\/ \u4ece\u961f\u5217\u4e2d\u79fb\u9664\u4efb\u52a1<br \/>\n    task.state &#061; TimerTask.EXECUTED; \/\/ \u5c06\u4efb\u52a1\u72b6\u6001\u6807\u8bb0\u4e3a\u5df2\u6267\u884c<br \/>\n}<\/p>\n<p>\u00a0\u5c31\u628a\u72b6\u6001\u8bbe\u7f6e\u4e3a\u00a0TimerTask.EXECUTED<\/p>\n<p>\u5982\u679c\u4efb\u52a1\u662f\u5468\u671f\u6027\u7684<\/p>\n<p> else {<br \/>\n    queue.rescheduleMin(<br \/>\n        task.period &lt; 0 ? currentTime &#8211; task.period<br \/>\n                        : executionTime &#043; task.period<br \/>\n    );<br \/>\n}<\/p>\n<p>1.task.period !&#061; 0 \u8868\u793a\u4efb\u52a1\u662f\u5468\u671f\u6027\u4efb\u52a1&#xff0c;\u5373\u4efb\u52a1\u9700\u8981\u6267\u884c\u591a\u6b21\u3002<\/p>\n<p>2.task.period &lt; 0 \u8868\u793a\u5468\u671f\u6027\u4efb\u52a1\u7684\u5468\u671f\u662f\u8d1f\u6570\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;task.period \u8868\u793a\u7684\u662f\u4e00\u4e2a\u76f8\u5bf9\u65f6\u95f4\u95f4\u9694&#xff0c;\u5e94\u8be5\u6839\u636e\u5f53\u524d\u65f6\u95f4\u6765\u8ba1\u7b97\u65b0\u7684\u6267\u884c\u65f6\u95f4\u3002\u6240\u4ee5 currentTime &#8211; task.period \u662f\u8ba1\u7b97\u4efb\u52a1\u7684\u4e0b\u6b21\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<p>3.\u5426\u5219&#xff0c;executionTime &#043; task.period \u8868\u793a\u4efb\u52a1\u7684\u4e0b\u6b21\u6267\u884c\u65f6\u95f4\u662f\u57fa\u4e8e\u4e0a\u4e00\u6b21\u7684\u6267\u884c\u65f6\u95f4\u52a0\u4e0a\u4e00\u4e2a\u56fa\u5b9a\u7684\u5468\u671f\u3002<\/p>\n<p>\u00a0<\/p>\n<p>\u4ee5\u4e0a\u7684\u8fd9\u4e9b\u6b65\u9aa4\u90fd\u662f\u8981\u52a0\u9501\u7684,\u4fdd\u8bc1\u539f\u5b50\u6027<\/p>\n<h4 id=\"%C2%A0%E7%AC%AC%E5%85%AD%E6%AD%A5%3A%20%E6%89%A7%E8%A1%8C\" style=\"background-color:transparent\">\u00a0\u7b2c\u4e94\u6b65: \u6267\u884c<\/h4>\n<p>\u5982\u679c\u00a0taskFired &#061;&#061; true , \u90a3\u4e48\u5c31\u6267\u884c\u7a0b\u5e8f<\/p>\n<p>  if (taskFired)  \/\/ Task fired; run it, holding no locks<br \/>\n                    task.run(); <\/p>\n<p>\u00a0<\/p>\n<p>\u6211\u4eec\u5c0f\u5c0f\u603b\u7ed3\u4e00\u4e0b\u5427<\/p>\n<p>\u5728 Java \u4e2d&#xff0c;\u53ef\u4ee5\u901a\u8fc7 Timer \u7c7b\u63d0\u4f9b\u5b9a\u65f6\u5668\u529f\u80fd\u3002\u5177\u4f53\u6765\u8bf4&#xff0c;\u5b9a\u65f6\u5668\u7684\u5b9e\u73b0\u4e3b\u8981\u4f9d\u8d56\u4e8e\u8c03\u7528 schedule() \u65b9\u6cd5\u3002<\/p>\n<p>schedule() \u65b9\u6cd5\u9700\u8981\u4f20\u5165\u4e24\u4e2a\u53c2\u6570&#xff1a;\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5b9e\u4f8b\u5316\u7684 TimerTask \u5bf9\u8c61&#xff08;TimerTask \u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b&#xff0c;\u5e76\u4e14\u5b9e\u73b0\u4e86 Runnable \u63a5\u53e3&#xff0c;\u9700\u8981\u91cd\u5199 run() \u65b9\u6cd5&#xff09;&#xff0c;\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a long delay&#xff0c;\u8868\u793a\u4efb\u52a1\u5ef6\u8fdf\u591a\u5c11\u6beb\u79d2\u540e\u6267\u884c\u3002<\/p>\n<p>\u5728 schedule() \u65b9\u6cd5\u5185\u90e8&#xff0c;\u53ea\u8981\u4f20\u5165\u7684 delay \u53c2\u6570\u6ca1\u6709\u95ee\u9898&#xff08;\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38&#xff09;&#xff0c;\u65b9\u6cd5\u5c31\u4f1a\u8c03\u7528\u5185\u90e8\u7684 sched() \u65b9\u6cd5&#xff0c;\u5c06\u4efb\u52a1\u52a0\u5165\u5230\u4e00\u4e2a\u4f18\u5148\u961f\u5217\u4e2d\u3002\u540c\u65f6&#xff0c;\u5524\u9192\u540e\u53f0\u7ebf\u7a0b TimerThread \u7684 mainLoop()&#xff0c;\u7531\u5b83\u4e0d\u65ad\u68c0\u67e5\u4efb\u52a1\u662f\u5426\u5230\u8fbe\u6267\u884c\u65f6\u95f4&#xff0c;\u4e00\u65e6\u5230\u8fbe&#xff0c;\u5c31\u8c03\u7528\u4efb\u52a1\u7684 run() \u65b9\u6cd5&#xff0c;\u6700\u7ec8\u5b9e\u73b0\u5b9a\u65f6\u5668\u6548\u679c\u3002<\/p>\n<h3 id=\"%E4%B8%BE%E4%B8%AA%E4%BE%8B%E5%AD%90%2C%E8%AF%B7%E7%9C%8B%E4%BB%A3%E7%A0%81%3A\" style=\"background-color:transparent\">\u4e3e\u4e2a\u4f8b\u5b50,\u8bf7\u770b\u4ee3\u7801: <\/h3>\n<p>import java.util.Timer;<br \/>\nimport java.util.TimerTask;<\/p>\n<p>\/\/ \u5b9a\u65f6\u5668<br \/>\npublic class Demo<br \/>\n{<br \/>\n    public static void main(String[] args) {<\/p>\n<p>        Timer timer &#061; new Timer();<br \/>\n        timer.schedule(new TimerTask() {<br \/>\n            &#064;Override<br \/>\n            public void run() {<br \/>\n                System.out.println(&#034;2000&#034;);<br \/>\n            }<br \/>\n        },2000);<br \/>\n        System.out.println(&#034;\u4e3b\u7ebf\u7a0b\u5f00\u59cb\u8dd1&#034;);<br \/>\n    }<br \/>\n}<br \/>\nimport java.util.Timer;<br \/>\nimport java.util.TimerTask;<\/p>\n<p>\/\/ \u5b9a\u65f6\u5668<\/p>\n<p>class  Mytimertask extends  TimerTask<br \/>\n{<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;2000&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>public class Demo<br \/>\n{<br \/>\n    public static void main(String[] args) {<br \/>\n        Timer timer &#061; new Timer();<br \/>\n        Mytimertask mytimertask &#061; new Mytimertask();<br \/>\n        timer.schedule(mytimertask,2000);<br \/>\n        System.out.println(&#034;\u4e3b\u7ebf\u7a0b\u5f00\u59cb\u8dd1&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u6211\u4eec\u5206\u522b\u901a\u8fc7\u5b9e\u73b0\u533f\u540d\u5185\u90e8\u7c7b\u548c\u5b9e\u73b0\u5b50\u7c7b\u7684\u65b9\u6cd5\u521b\u5efa\u4e86\u4e00\u4e2a TimerTask \u5bf9\u8c61,\u5b9e\u73b0\u4e86schedule\u65b9\u6cd5\u00a0<\/p>\n<p>\u6548\u679c\u5982\u4e0b:\u00a0<\/p>\n<p>\u9996\u5148\u6253\u5370&#034;\u4e3b\u7ebf\u7a0b\u5f00\u59cb\u8dd1&#034;,\u8fc7\u4e86\u4e24\u79d2\u4ee5\u540e\u6253\u5370&#034;2000&#034;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"90\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250429011451-6810280b04a2f.jpg\" width=\"550\" \/>\u200b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u7b80\u5355\u4ecb\u7ecd\u548c\u7b80\u5355\u4e3e\u4f8b\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<h2 id=\"%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E5%AE%9A%E6%97%B6%E5%99%A8\" style=\"background-color:transparent\">\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u5b9a\u65f6\u5668<\/h2>\n<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u81ea\u5df1\u52a8\u624b\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u5b9a\u65f6\u5668,\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\u8bb2\u89e3\u6211\u4eec\u4e5f\u80fd\u770b\u51fa\u6765<\/p>\n<p>\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a TimerTask , \u4e00\u4e2a Timer.\u00a0 \u7136\u540e\u624b\u52a8\u5b9e\u73b0schedule()\u65b9\u6cd5 \u548c mainLoop() \u65b9\u6cd5<\/p>\n<p>\u00a0Timer \u7c7b<\/p>\n<p>class  MyTimerTask<br \/>\n{<br \/>\n    public Runnable runnable;<\/p>\n<p>     public long time;<\/p>\n<p>    public MyTimerTask(Runnable runnable, long delay) {<br \/>\n        this.runnable &#061; runnable;<br \/>\n        this.time &#061; System.currentTimeMillis()&#043;delay;<br \/>\n    }<br \/>\n    public Runnable getRunnable() {<br \/>\n        return runnable;<br \/>\n    }<br \/>\n    public long getTime() {<br \/>\n        return time;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u00a0\u4e3a\u4ec0\u4e48\u624b\u52a8\u5b9e\u73b0\u5b9a\u65f6\u5668\u65f6\u4f7f\u7528Runnable&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u8981\u5b83\u7684run()\u65b9\u6cd5,\u4e0d\u9700\u8981\u522b\u7684,TimerTask \u6240\u63d0\u4f9b\u7684\u5176\u4ed6\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\u6211\u4eec\u6682\u65f6\u4e0d\u5f04<\/p>\n<p>\u00a0TimerTask\u7c7b<\/p>\n<p>\u5728\u6784\u9020\u65b9\u6cd5\u4e2d\u65b0\u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u5bf9\u8c61<\/p>\n<p>class MyTimer<br \/>\n{<br \/>\n        PriorityQueue&lt;MyTimerTask&gt; priorityQueue &#061; new PriorityQueue&lt;&gt;(new Comparator&lt;MyTimerTask&gt;() {<br \/>\n            &#064;Override<br \/>\n            public int compare(MyTimerTask o1, MyTimerTask o2) {<br \/>\n                 return Long.compare(o1.time,o2.time);<br \/>\n            }<br \/>\n        });<br \/>\n        Object locker &#061; new Object();<br \/>\n        public  void schedule(Runnable runnable,long delay)<br \/>\n        {<br \/>\n            synchronized (locker)<br \/>\n            {<br \/>\n                priorityQueue.offer(new MyTimerTask(runnable,delay));<br \/>\n                locker.notify();<br \/>\n            }<br \/>\n        }<br \/>\npublic  MyTimer()<br \/>\n{<br \/>\n    Thread thread &#061; new Thread(() -&gt; {<br \/>\n        while(true)<br \/>\n        {<br \/>\n            try {<br \/>\n                synchronized (locker)<br \/>\n                {<br \/>\n                    while(priorityQueue.isEmpty())<br \/>\n                    {<br \/>\n                        \/\/ \u5982\u679c\u662f\u7a7a\u7684\u5c31\u963b\u585e,\u76f4\u5230\u5524\u9192<br \/>\n                        locker.wait();<br \/>\n                    }<br \/>\n                    MyTimerTask myTimerTask &#061; priorityQueue.peek();<br \/>\n                    long now &#061; System.currentTimeMillis();<br \/>\n                    if (now &gt;&#061; myTimerTask.getTime()) {<br \/>\n                        myTimerTask.getRunnable().run();<br \/>\n                        priorityQueue.poll();<br \/>\n                    } else {<br \/>\n                        locker.wait(myTimerTask.getTime() &#8211; now);<br \/>\n                    }<\/p>\n<p>                }<br \/>\n            }<br \/>\n            catch (InterruptedException e)<br \/>\n            {<br \/>\n                e.printStackTrace();<br \/>\n            }<\/p>\n<p>        }<br \/>\n    });<br \/>\n    thread.start();<br \/>\n}<br \/>\n}<\/p>\n<p>\u00a0\u6d4b\u8bd5:<\/p>\n<p>public  class Demo18 {<br \/>\n    public static void main(String[] args) {<br \/>\n        MyTimer myTimer &#061; new MyTimer();<br \/>\n        myTimer.schedule(new Runnable() {<br \/>\n            &#064;Override<br \/>\n            public void run() {<br \/>\n                System.out.println(3000);<br \/>\n            }<br \/>\n        },3000);<br \/>\n\/\/        1\ufe0f\u20e3 \u521b\u5efa\u4e86\u4e00\u4e2a\u533f\u540d\u5185\u90e8\u7c7b&#xff0c;\u5b9e\u73b0\u4e86 Runnable \u63a5\u53e3\u3002<br \/>\n\/\/        2\ufe0f\u20e3 \u5fc5\u987b\u91cd\u5199 run() \u65b9\u6cd5&#xff0c;\u5426\u5219\u63a5\u53e3\u6ca1\u6709\u5177\u4f53\u6267\u884c\u5185\u5bb9\u3002<br \/>\n        System.out.println(&#034;\u7a0b\u5e8f\u5f00\u59cb\u6267\u884c&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7ed3\u679c\u5982\u4e0b:<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250429011451-6810280b45cad.png\" \/>\u00a0<\/p>\n<h2 id=\"%E7%BB%93%E5%B0%BE%C2%A0\">\u7ed3\u5c3e\u00a0<\/h2>\n<p>\u00a0<\/p>\n<p>\u53c8\u662f\u5199\u4e86\u5f88\u4e45\u7684\u9ad8\u8d28\u91cf\u535a\u5ba2,\u5e0c\u671b\u80fd\u5bf9\u4eba\u6709\u5e2e\u52a9\u5427,\u8c22\u8c22\u5927\u5bb6!!<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e71\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u80fd\u529b\u5df2\u7ecf\u6210\u4e3a\u7a0b\u5e8f\u5458\u5fc5\u987b\u638c\u63e1\u7684\u4e00\u9879\u6838\u5fc3\u6280\u80fd\u3002\u968f\u7740\u8ba1\u7b97\u673a\u786c\u4ef6\u7684\u4e0d\u65ad\u5347\u7ea7\uff0c\u5355\u6838CPU\u65e9\u5df2\u65e0\u6cd5\u6ee1\u8db3\u590d\u6742\u5e94\u7528\u7684\u6027\u80fd\u9700\u6c42\uff0c\u591a\u6838\u5e76\u884c\u8fd0\u7b97\u5df2\u6210\u4e3a\u4e3b\u6d41\u3002\u800c\u591a\u7ebf\u7a0b\u6b63\u662f\u5b9e\u73b0\u8d44\u6e90\u6700\u5927\u5316\u5229\u7528\u3001\u4efb\u52a1\u9ad8\u6548\u5e76\u884c\u6267\u884c\u7684\u57fa\u7840\u624b\u6bb5\u3002\u800c\u672c\u535a\u5ba2\u662f\u7b14\u8005\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u7b2c\u4e94\u7bc7\u535a\u5ba2!\u524d\u9762\u56db\u7bc7\u90fd\u5728\u4e0b\u9762\u7684URL\u4e2d,\u5e0c\u671b\u80fd\u5f97\u5230\u5927\u4f6c\u4eec\u7684\u9605\u8bfb\u548c\u6307\u70b9!!!\u591a\u7ebf\u7a0b\u7f16\u7a0b_callJJ\u7684\u535a\u5ba2-CSDN\u535a\u5ba2\u672c\u671f\u6211\u4eec\u4ecb\u7ecd\u7684\u662f\u5b9a\u65f6\u5668,\u7136\u540e\u7ffb\u770b\u5e76\u4e14\u4ecb\u7ecd\u5b83\u7684\u6e90\u7801\u3002<\/p>\n","protected":false},"author":2,"featured_media":34286,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,426,81,2902,2903,190,427],"topic":[],"class_list":["post-34288","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-jvm","tag-python","tag-2902","tag-2903","tag-190","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \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\/34288.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e71\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u80fd\u529b\u5df2\u7ecf\u6210\u4e3a\u7a0b\u5e8f\u5458\u5fc5\u987b\u638c\u63e1\u7684\u4e00\u9879\u6838\u5fc3\u6280\u80fd\u3002\u968f\u7740\u8ba1\u7b97\u673a\u786c\u4ef6\u7684\u4e0d\u65ad\u5347\u7ea7\uff0c\u5355\u6838CPU\u65e9\u5df2\u65e0\u6cd5\u6ee1\u8db3\u590d\u6742\u5e94\u7528\u7684\u6027\u80fd\u9700\u6c42\uff0c\u591a\u6838\u5e76\u884c\u8fd0\u7b97\u5df2\u6210\u4e3a\u4e3b\u6d41\u3002\u800c\u591a\u7ebf\u7a0b\u6b63\u662f\u5b9e\u73b0\u8d44\u6e90\u6700\u5927\u5316\u5229\u7528\u3001\u4efb\u52a1\u9ad8\u6548\u5e76\u884c\u6267\u884c\u7684\u57fa\u7840\u624b\u6bb5\u3002\u800c\u672c\u535a\u5ba2\u662f\u7b14\u8005\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u7b2c\u4e94\u7bc7\u535a\u5ba2!\u524d\u9762\u56db\u7bc7\u90fd\u5728\u4e0b\u9762\u7684URL\u4e2d,\u5e0c\u671b\u80fd\u5f97\u5230\u5927\u4f6c\u4eec\u7684\u9605\u8bfb\u548c\u6307\u70b9!!!\u591a\u7ebf\u7a0b\u7f16\u7a0b_callJJ\u7684\u535a\u5ba2-CSDN\u535a\u5ba2\u672c\u671f\u6211\u4eec\u4ecb\u7ecd\u7684\u662f\u5b9a\u65f6\u5668,\u7136\u540e\u7ffb\u770b\u5e76\u4e14\u4ecb\u7ecd\u5b83\u7684\u6e90\u7801\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/34288.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-29T01:14:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250429011451-6810280b04a2f.jpg\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/34288.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/34288.html\",\"name\":\"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-29T01:14:52+00:00\",\"dateModified\":\"2025-04-29T01:14:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/34288.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/34288.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/34288.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)]\"}]},{\"@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":"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \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\/34288.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.5k\u6b21\uff0c\u70b9\u8d5e71\u6b21\uff0c\u6536\u85cf54\u6b21\u3002\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u80fd\u529b\u5df2\u7ecf\u6210\u4e3a\u7a0b\u5e8f\u5458\u5fc5\u987b\u638c\u63e1\u7684\u4e00\u9879\u6838\u5fc3\u6280\u80fd\u3002\u968f\u7740\u8ba1\u7b97\u673a\u786c\u4ef6\u7684\u4e0d\u65ad\u5347\u7ea7\uff0c\u5355\u6838CPU\u65e9\u5df2\u65e0\u6cd5\u6ee1\u8db3\u590d\u6742\u5e94\u7528\u7684\u6027\u80fd\u9700\u6c42\uff0c\u591a\u6838\u5e76\u884c\u8fd0\u7b97\u5df2\u6210\u4e3a\u4e3b\u6d41\u3002\u800c\u591a\u7ebf\u7a0b\u6b63\u662f\u5b9e\u73b0\u8d44\u6e90\u6700\u5927\u5316\u5229\u7528\u3001\u4efb\u52a1\u9ad8\u6548\u5e76\u884c\u6267\u884c\u7684\u57fa\u7840\u624b\u6bb5\u3002\u800c\u672c\u535a\u5ba2\u662f\u7b14\u8005\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u7b2c\u4e94\u7bc7\u535a\u5ba2!\u524d\u9762\u56db\u7bc7\u90fd\u5728\u4e0b\u9762\u7684URL\u4e2d,\u5e0c\u671b\u80fd\u5f97\u5230\u5927\u4f6c\u4eec\u7684\u9605\u8bfb\u548c\u6307\u70b9!!!\u591a\u7ebf\u7a0b\u7f16\u7a0b_callJJ\u7684\u535a\u5ba2-CSDN\u535a\u5ba2\u672c\u671f\u6211\u4eec\u4ecb\u7ecd\u7684\u662f\u5b9a\u65f6\u5668,\u7136\u540e\u7ffb\u770b\u5e76\u4e14\u4ecb\u7ecd\u5b83\u7684\u6e90\u7801\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/34288.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-29T01:14:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250429011451-6810280b04a2f.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/34288.html","url":"https:\/\/www.wsisp.com\/helps\/34288.html","name":"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)] - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-29T01:14:52+00:00","dateModified":"2025-04-29T01:14:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/34288.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/34288.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/34288.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5b9a\u65f6\u5668\u7684\u6e90\u7801\u4ecb\u7ecd\u4e0e\u7b80\u5355\u5b9e\u73b0\u2014\u2014\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7b80\u5355\u6848\u4f8b[\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7bc7(5)]"}]},{"@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\/34288","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=34288"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/34288\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/34286"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=34288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=34288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=34288"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=34288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}