\u5982\u679c\u60f3\u8981\u591a\u4e2a\u5b9a\u65f6\u4efb\u52a1\u91cd\u53e0\u6267\u884c<\/strong><\/div>\n\u9700\u8981\u624b\u52a8\u6307\u5b9a\u7ebf\u7a0b\u6c60\uff0c\u5982\u4e0b<\/p>\n
\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.scheduling.TaskScheduler;\r\nimport org.springframework.scheduling.annotation.EnableScheduling;\r\nimport org.springframework.scheduling.annotation.Scheduled;\r\nimport org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;\r\nimport org.springframework.stereotype.Component; \r\nimport java.time.LocalDateTime;\r\n \r\n@Component\r\n@EnableScheduling\r\npublic class MyScheduled {\r\n \r\n @Bean\r\n public TaskScheduler taskScheduler() {\r\n ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();\r\n taskScheduler.setPoolSize(50);\r\n return taskScheduler;\r\n }\r\n \r\n @Scheduled(cron = \"0\/5 * * * * ?\")\r\n public void execute1(){\r\n String curName = Thread.currentThread().getName() ;\r\n System.out.println(\"\u5f53\u524d\u65f6\u95f4:\"+LocalDateTime.now()+\" \u4efb\u52a1execute1\u5bf9\u5e94\u7684\u7ebf\u7a0b\u540d: \"+curName);\r\n try {\r\n Thread.sleep(1000);\r\n } catch (Exception e) {\r\n e.printStackTrace();\r\n } \r\n }\r\n \r\n @Scheduled(cron = \"0\/5 * * * * ?\")\r\n public void execute2(){ \r\n String curName = Thread.currentThread().getName() ;\r\n System.out.println(\"\u5f53\u524d\u65f6\u95f4:\"+LocalDateTime.now()+\" \u4efb\u52a1execute2\u5bf9\u5e94\u7684\u7ebf\u7a0b\u540d: \"+curName);\r\n try {\r\n Thread.sleep(1000);\r\n } catch (InterruptedException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n}\r\n<\/pre>\n\u6b64\u65f6\uff0c\u591a\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff0c\u662f\u4e0d\u901a\u7684\u7ebf\u7a0b\u6267\u884c\uff0c\u540c\u65f6\uff0c\u5b9a\u65f6\u4efb\u52a1\u53ef\u4ee5\u91cd\u53e0\u6267\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u53ea\u9700\u5728springBoot\u542f\u52a8\u7c7b\u4e0a\u6dfb\u52a0 \u5982\u4e0b\u4ee3\u7801\u5373\u53ef\uff1a @Bean public TaskScheduler […]<\/p>\n","protected":false},"author":362,"featured_media":233353,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-233351","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\/233351","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\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=233351"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233351\/revisions"}],"predecessor-version":[{"id":233355,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233351\/revisions\/233355"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/233353"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=233351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=233351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=233351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}