{"id":37371,"date":"2025-05-15T22:28:03","date_gmt":"2025-05-15T14:28:03","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/37371.html"},"modified":"2025-05-15T22:28:03","modified_gmt":"2025-05-15T14:28:03","slug":"spring%e4%b8%ad%e7%9a%84async%e6%b3%a8%e8%a7%a3%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/37371.html","title":{"rendered":"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3"},"content":{"rendered":"<h4>\u4e00\u3001\u6838\u5fc3\u529f\u80fd\u4e0e\u4f5c\u7528<\/h4>\n<p>&#064;Async \u662fSpring\u6846\u67b6\u63d0\u4f9b\u7684\u5f02\u6b65\u65b9\u6cd5\u6267\u884c\u6ce8\u89e3&#xff0c;\u7528\u4e8e\u5c06\u65b9\u6cd5\u6807\u8bb0\u4e3a\u5f02\u6b65\u4efb\u52a1&#xff0c;\u4f7f\u5176\u5728\u72ec\u7acb\u7ebf\u7a0b\u4e2d\u6267\u884c&#xff0c;\u4ece\u800c\u63d0\u5347\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u541e\u5410\u91cf\u3002\u5176\u4e3b\u8981\u4f5c\u7528\u5305\u62ec&#xff1a;<\/p>\n<li>\u975e\u963b\u585e\u8c03\u7528&#xff1a;\u4e3b\u7ebf\u7a0b\u8c03\u7528\u88ab\u6807\u8bb0\u65b9\u6cd5\u540e\u7acb\u5373\u8fd4\u56de&#xff0c;\u907f\u514dI\/O\u5bc6\u96c6\u578b\u4efb\u52a1&#xff08;\u5982\u6587\u4ef6\u5904\u7406\u3001\u8fdc\u7a0bAPI\u8c03\u7528&#xff09;\u7684\u963b\u585e\u3002<\/li>\n<li>\u8d44\u6e90\u4f18\u5316&#xff1a;\u901a\u8fc7\u7ebf\u7a0b\u6c60\u7ba1\u7406\u5e76\u53d1\u4efb\u52a1&#xff0c;\u63d0\u5347\u7cfb\u7edf\u8d44\u6e90\u5229\u7528\u7387\u3002<\/li>\n<li>\u7b80\u5316\u591a\u7ebf\u7a0b\u5f00\u53d1&#xff1a;\u65e0\u9700\u624b\u52a8\u521b\u5efa\u548c\u7ba1\u7406\u7ebf\u7a0b&#xff0c;\u4ec5\u9700\u901a\u8fc7\u6ce8\u89e3\u58f0\u660e\u5373\u53ef\u5b9e\u73b0\u5f02\u6b65\u903b\u8f91\u3002<\/li>\n<p>\u524d\u4e9b\u5929\u53d1\u73b0\u4e86\u4e00\u4e2a\u5de8\u725b\u7684\u4eba\u5de5\u667a\u80fd\u5b66\u4e60\u7f51\u7ad9&#xff0c;\u901a\u4fd7\u6613\u61c2&#xff0c;\u98ce\u8da3\u5e7d\u9ed8&#xff0c;\u5fcd\u4e0d\u4f4f\u5206\u4eab\u4e00\u4e0b\u7ed9\u5927\u5bb6\u3002\u70b9\u51fb\u8df3\u8f6c\u5230\u7f51\u7ad9<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250515142802-6825f9f224d4a.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h4>\u4e8c\u3001\u5b9e\u73b0\u539f\u7406<\/h4>\n<li>\n<p>\u52a8\u6001\u4ee3\u7406\u673a\u5236 Spring\u901a\u8fc7AOP&#xff08;\u9762\u5411\u5207\u9762\u7f16\u7a0b&#xff09;\u4e3a\u88ab&#064;Async\u6807\u8bb0\u7684\u65b9\u6cd5\u751f\u6210\u4ee3\u7406\u5bf9\u8c61\u3002\u5f53\u8c03\u7528\u5f02\u6b65\u65b9\u6cd5\u65f6&#xff0c;\u4ee3\u7406\u5bf9\u8c61\u5c06\u4efb\u52a1\u63d0\u4ea4\u7ed9TaskExecutor\u7ebf\u7a0b\u6c60\u6267\u884c\u3002<\/p>\n<ul>\n<li>\n<p>\u4ee3\u7406\u7c7b\u578b&#xff1a;\u6839\u636e\u76ee\u6807\u7c7b\u662f\u5426\u5b9e\u73b0\u63a5\u53e3&#xff0c;\u9009\u62e9JDK\u52a8\u6001\u4ee3\u7406\u6216CGLIB\u4ee3\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u62e6\u622a\u903b\u8f91&#xff1a;AsyncExecutionInterceptor\u62e6\u622a\u65b9\u6cd5\u8c03\u7528&#xff0c;\u5c06\u4efb\u52a1\u63d0\u4ea4\u81f3\u7ebf\u7a0b\u6c60\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7ebf\u7a0b\u6c60\u7ba1\u7406<\/p>\n<ul>\n<li>\n<p>\u9ed8\u8ba4\u7ebf\u7a0b\u6c60&#xff1a;\u4f7f\u7528SimpleAsyncTaskExecutor&#xff08;\u6bcf\u6b21\u8c03\u7528\u521b\u5efa\u65b0\u7ebf\u7a0b&#xff0c;\u4e0d\u63a8\u8350\u751f\u4ea7\u73af\u5883\u4f7f\u7528&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60&#xff1a;\u901a\u8fc7ThreadPoolTaskExecutor\u914d\u7f6e\u6838\u5fc3\u7ebf\u7a0b\u6570\u3001\u961f\u5217\u5bb9\u91cf\u7b49\u53c2\u6570&#xff0c;\u907f\u514d\u8d44\u6e90\u8017\u5c3d\u95ee\u9898\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u89e6\u53d1 \u9700\u5728\u914d\u7f6e\u7c7b\u6dfb\u52a0&#064;EnableAsync\u542f\u7528\u5f02\u6b65\u652f\u6301&#xff0c;\u5426\u5219\u6ce8\u89e3\u65e0\u6548\u3002<\/p>\n<\/li>\n<hr \/>\n<h4>\u4e09\u3001\u4f7f\u7528\u573a\u666f\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h4>\n<li>\n<p>\u5178\u578b\u573a\u666f<\/p>\n<ul>\n<li>\n<p>\u540e\u53f0\u4efb\u52a1&#xff1a;\u90ae\u4ef6\u53d1\u9001\u3001\u65e5\u5fd7\u8bb0\u5f55\u3001\u62a5\u8868\u751f\u6210\u7b49\u8017\u65f6\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e76\u884c\u5904\u7406&#xff1a;\u6279\u91cf\u6570\u636e\u5904\u7406\u3001\u591a\u670d\u52a1\u5e76\u53d1\u8c03\u7528\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u57fa\u7840\u7528\u6cd5<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">OrderService<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Async<\/span>  <span class=\"token comment\">\/\/ \u65e0\u8fd4\u56de\u503c\u5f02\u6b65\u65b9\u6cd5<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">processOrderAsync<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Order<\/span> order<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u5904\u7406\u8ba2\u5355\u903b\u8f91<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Async<\/span>  <span class=\"token comment\">\/\/ \u5e26\u8fd4\u56de\u503c\u7684\u5f02\u6b65\u65b9\u6cd5<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Future<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Report<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token function\">generateReportAsync<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">AsyncResult<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span>report<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8fd4\u56de\u503c\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fd4\u56devoid&#xff1a;\u9002\u7528\u4e8e\u65e0\u9700\u83b7\u53d6\u7ed3\u679c\u7684\u573a\u666f\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd4\u56deFuture&lt;T&gt;\u6216CompletableFuture&lt;T&gt;&#xff1a;\u7528\u4e8e\u5f02\u6b65\u83b7\u53d6\u6267\u884c\u7ed3\u679c\u6216\u5f02\u5e38\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u914d\u7f6e<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;EnableAsync<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">AsyncConfig<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">AsyncConfigurer<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Executor<\/span> <span class=\"token function\">getAsyncExecutor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">ThreadPoolTaskExecutor<\/span> executor <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ThreadPoolTaskExecutor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">setCorePoolSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">setMaxPoolSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">setQueueCapacity<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">setThreadNamePrefix<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;CustomAsync-&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">initialize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> executor<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<ul>\n<li>\u63a8\u8350\u53c2\u6570&#xff1a;\u6839\u636e\u4e1a\u52a1\u8d1f\u8f7d\u8bbe\u7f6ecorePoolSize&#xff08;\u6838\u5fc3\u7ebf\u7a0b\u6570&#xff09;\u548cqueueCapacity&#xff08;\u961f\u5217\u5bb9\u91cf&#xff09;&#xff0c;\u907f\u514d\u4efb\u52a1\u5806\u79ef\u5bfc\u81f4OOM\u3002<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u56db\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h4>\n<li>\n<p>\u6ce8\u89e3\u5931\u6548\u573a\u666f<\/p>\n<ul>\n<li>\n<p>\u540c\u7c7b\u8c03\u7528&#xff1a;\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\u901a\u8fc7this\u8c03\u7528&#064;Async\u65b9\u6cd5&#xff0c;\u4ee3\u7406\u65e0\u6cd5\u62e6\u622a&#xff08;\u9700\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u8c03\u7528&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u975epublic\u65b9\u6cd5&#xff1a;\u4ec5\u652f\u6301public\u6216protected\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p>\u672a\u542f\u7528\u5f02\u6b65\u652f\u6301&#xff1a;\u4e3b\u914d\u7f6e\u7c7b\u672a\u6dfb\u52a0&#064;EnableAsync\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5f02\u5e38\u5904\u7406<\/p>\n<ul>\n<li>\n<p>\u672a\u6355\u83b7\u5f02\u5e38&#xff1a;\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5f02\u6b65\u65b9\u6cd5\u629b\u51fa\u7684\u5f02\u5e38\u4e0d\u4f1a\u4f20\u64ad\u5230\u8c03\u7528\u65b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528try-catch\u5305\u88f9\u5f02\u6b65\u65b9\u6cd5\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u73b0AsyncUncaughtExceptionHandler\u63a5\u53e3\u5168\u5c40\u5904\u7406\u5f02\u5e38\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u5931\u6548 \u5f02\u6b65\u65b9\u6cd5\u9ed8\u8ba4\u4e0d\u7ee7\u627f\u8c03\u7528\u65b9\u7684\u4e8b\u52a1\u4e0a\u4e0b\u6587\u3002\u82e5\u9700\u4e8b\u52a1\u652f\u6301&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5728\u5f02\u6b65\u65b9\u6cd5\u4e0a\u6dfb\u52a0&#064;Transactional\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528Propagation.REQUIRES_NEW\u4f20\u64ad\u7ea7\u522b\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u4e94\u3001\u9ad8\u7ea7\u7528\u6cd5\u4e0e\u6269\u5c55<\/h4>\n<li>\n<p>\u4e0a\u4e0b\u6587\u4f20\u9012 \u5f02\u6b65\u7ebf\u7a0b\u9ed8\u8ba4\u4e0d\u7ee7\u627f\u4e3b\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587&#xff08;\u5982SecurityContext&#xff09;\u3002\u53ef\u901a\u8fc7TaskDecorator\u590d\u5236\u4e0a\u4e0b\u6587\u4fe1\u606f&#xff1a;<\/p>\n<p> executor<span class=\"token punctuation\">.<\/span><span class=\"token function\">setTaskDecorator<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ContextCopyingTaskDecorator<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u7ec4\u5408\u6ce8\u89e3\u4f18\u5316 \u81ea\u5b9a\u4e49\u6ce8\u89e3&#xff08;\u5982&#064;AsyncWithLogging&#xff09;\u7ed3\u5408&#064;Async\u4e0e\u65e5\u5fd7\u5207\u9762&#xff0c;\u5b9e\u73b0\u5f02\u6b65\u4efb\u52a1\u7684\u7edf\u4e00\u76d1\u63a7\u3002<\/p>\n<\/li>\n<li>\n<p>\u52a8\u6001\u7ebf\u7a0b\u6c60\u9009\u62e9 \u5728&#064;Async\u6ce8\u89e3\u4e2d\u6307\u5b9a\u7ebf\u7a0b\u6c60\u540d\u79f0&#xff1a;<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Async<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;reportExecutor&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">generateReport<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span>\n <\/li>\n<hr \/>\n<h4>\u603b\u7ed3<\/h4>\n<p>&#064;Async\u901a\u8fc7\u7b80\u5316\u7684\u6ce8\u89e3\u9a71\u52a8\u6a21\u578b&#xff0c;\u4e3aSpring\u5e94\u7528\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u5f02\u6b65\u5904\u7406\u80fd\u529b\u3002\u5173\u952e\u5b9e\u8df5\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u907f\u514d\u9ed8\u8ba4\u7ebf\u7a0b\u6c60&#xff1a;\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u63d0\u5347\u7a33\u5b9a\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f02\u5e38\u515c\u5e95\u673a\u5236&#xff1a;\u9632\u6b62\u4efb\u52a1\u9759\u9ed8\u5931\u8d25\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0a\u4e0b\u6587\u9694\u79bb&#xff1a;\u6ce8\u610f\u7ebf\u7a0b\u95f4\u6570\u636e\u9694\u79bb\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u52a1\u517c\u5bb9\u6027&#xff1a;\u663e\u5f0f\u58f0\u660e\u4e8b\u52a1\u8fb9\u754c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u590d\u6742\u573a\u666f&#xff08;\u5982\u5206\u5e03\u5f0f\u4efb\u52a1\u8c03\u5ea6&#xff09;&#xff0c;\u5efa\u8bae\u7ed3\u5408Spring Batch\u6216\u6d88\u606f\u961f\u5217&#xff08;\u5982RabbitMQ&#xff09;\u5b9e\u73b0\u66f4\u9ad8\u7ea7\u522b\u7684\u5f02\u6b65\u67b6\u6784\u3002<\/p>\n<hr \/>\n<p>spring\u4e2d\u7684&#064;PropertySource\u6ce8\u89e3\u8be6\u89e3 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002@Async\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u5b9e\u73b0\u5f02\u6b65\u65b9\u6cd5\u6267\u884c\u7684\u6ce8\u89e3\uff0c\u80fd\u591f\u63d0\u5347\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u541e\u5410\u91cf\u3002\u5176\u6838\u5fc3\u529f\u80fd\u5305\u62ec\u975e\u963b\u585e\u8c03\u7528\u3001\u8d44\u6e90\u4f18\u5316\u548c\u7b80\u5316\u591a\u7ebf\u7a0b\u5f00\u53d1\u3002\u5b9e\u73b0\u539f\u7406\u57fa\u4e8e\u52a8\u6001\u4ee3\u7406\u673a\u5236\u548c\u7ebf\u7a0b\u6c60\u7ba1\u7406\uff0c\u9ed8\u8ba4\u4f7f\u7528SimpleAsyncTaskExecutor\uff0c\u4f46\u63a8\u8350\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u4f7f\u7528\u573a\u666f\u6db5\u76d6\u540e\u53f0\u4efb\u52a1\u548c\u5e76\u884c\u5904\u7406\uff0c\u57fa\u7840\u7528\u6cd5\u5305\u62ec\u65e0\u8fd4\u56de\u503c\u548c\u5e26\u8fd4\u56de\u503c\u7684\u5f02\u6b65\u65b9\u6cd5\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u6ce8\u89e3\u5931\u6548\u3001\u5f02\u5e38\u5904\u7406\u548c\u4e8b\u52a1\u5931\u6548\uff0c\u9700\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u3001\u5f02\u5e38\u6355\u83b7\u548c\u663e\u5f0f\u4e8b\u52a1\u58f0\u660e\u89e3\u51b3\u3002\u9ad8\u7ea7\u7528\u6cd5\u6d89\u53ca\u4e0a\u4e0b\u6587\u4f20\u9012\u3001\u7ec4\u5408\u6ce8\u89e3\u4f18\u5316\u548c\u52a8\u6001\u7ebf\u7a0b\u6c60\u9009\u62e9\u3002\u603b\u7ed3\u4e2d\u5f3a\u8c03\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u3001\u5f02\u5e38\u515c<\/p>\n","protected":false},"author":2,"featured_media":37370,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3235,99,101,292,1637],"topic":[],"class_list":["post-37371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-async","tag-java","tag-spring","tag-292","tag-1637"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \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\/37371.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002@Async\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u5b9e\u73b0\u5f02\u6b65\u65b9\u6cd5\u6267\u884c\u7684\u6ce8\u89e3\uff0c\u80fd\u591f\u63d0\u5347\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u541e\u5410\u91cf\u3002\u5176\u6838\u5fc3\u529f\u80fd\u5305\u62ec\u975e\u963b\u585e\u8c03\u7528\u3001\u8d44\u6e90\u4f18\u5316\u548c\u7b80\u5316\u591a\u7ebf\u7a0b\u5f00\u53d1\u3002\u5b9e\u73b0\u539f\u7406\u57fa\u4e8e\u52a8\u6001\u4ee3\u7406\u673a\u5236\u548c\u7ebf\u7a0b\u6c60\u7ba1\u7406\uff0c\u9ed8\u8ba4\u4f7f\u7528SimpleAsyncTaskExecutor\uff0c\u4f46\u63a8\u8350\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u4f7f\u7528\u573a\u666f\u6db5\u76d6\u540e\u53f0\u4efb\u52a1\u548c\u5e76\u884c\u5904\u7406\uff0c\u57fa\u7840\u7528\u6cd5\u5305\u62ec\u65e0\u8fd4\u56de\u503c\u548c\u5e26\u8fd4\u56de\u503c\u7684\u5f02\u6b65\u65b9\u6cd5\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u6ce8\u89e3\u5931\u6548\u3001\u5f02\u5e38\u5904\u7406\u548c\u4e8b\u52a1\u5931\u6548\uff0c\u9700\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u3001\u5f02\u5e38\u6355\u83b7\u548c\u663e\u5f0f\u4e8b\u52a1\u58f0\u660e\u89e3\u51b3\u3002\u9ad8\u7ea7\u7528\u6cd5\u6d89\u53ca\u4e0a\u4e0b\u6587\u4f20\u9012\u3001\u7ec4\u5408\u6ce8\u89e3\u4f18\u5316\u548c\u52a8\u6001\u7ebf\u7a0b\u6c60\u9009\u62e9\u3002\u603b\u7ed3\u4e2d\u5f3a\u8c03\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u3001\u5f02\u5e38\u515c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/37371.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-15T14:28:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250515142802-6825f9f224d4a.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=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37371.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/37371.html\",\"name\":\"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-15T14:28:03+00:00\",\"dateModified\":\"2025-05-15T14:28:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/37371.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/37371.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37371.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3\"}]},{\"@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":"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \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\/37371.html","og_locale":"zh_CN","og_type":"article","og_title":"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf9\u6b21\u3002@Async\u662fSpring\u6846\u67b6\u4e2d\u7528\u4e8e\u5b9e\u73b0\u5f02\u6b65\u65b9\u6cd5\u6267\u884c\u7684\u6ce8\u89e3\uff0c\u80fd\u591f\u63d0\u5347\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u541e\u5410\u91cf\u3002\u5176\u6838\u5fc3\u529f\u80fd\u5305\u62ec\u975e\u963b\u585e\u8c03\u7528\u3001\u8d44\u6e90\u4f18\u5316\u548c\u7b80\u5316\u591a\u7ebf\u7a0b\u5f00\u53d1\u3002\u5b9e\u73b0\u539f\u7406\u57fa\u4e8e\u52a8\u6001\u4ee3\u7406\u673a\u5236\u548c\u7ebf\u7a0b\u6c60\u7ba1\u7406\uff0c\u9ed8\u8ba4\u4f7f\u7528SimpleAsyncTaskExecutor\uff0c\u4f46\u63a8\u8350\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u4ee5\u4f18\u5316\u6027\u80fd\u3002\u4f7f\u7528\u573a\u666f\u6db5\u76d6\u540e\u53f0\u4efb\u52a1\u548c\u5e76\u884c\u5904\u7406\uff0c\u57fa\u7840\u7528\u6cd5\u5305\u62ec\u65e0\u8fd4\u56de\u503c\u548c\u5e26\u8fd4\u56de\u503c\u7684\u5f02\u6b65\u65b9\u6cd5\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u6ce8\u89e3\u5931\u6548\u3001\u5f02\u5e38\u5904\u7406\u548c\u4e8b\u52a1\u5931\u6548\uff0c\u9700\u901a\u8fc7\u4f9d\u8d56\u6ce8\u5165\u3001\u5f02\u5e38\u6355\u83b7\u548c\u663e\u5f0f\u4e8b\u52a1\u58f0\u660e\u89e3\u51b3\u3002\u9ad8\u7ea7\u7528\u6cd5\u6d89\u53ca\u4e0a\u4e0b\u6587\u4f20\u9012\u3001\u7ec4\u5408\u6ce8\u89e3\u4f18\u5316\u548c\u52a8\u6001\u7ebf\u7a0b\u6c60\u9009\u62e9\u3002\u603b\u7ed3\u4e2d\u5f3a\u8c03\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6c60\u3001\u5f02\u5e38\u515c","og_url":"https:\/\/www.wsisp.com\/helps\/37371.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-15T14:28:03+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250515142802-6825f9f224d4a.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/37371.html","url":"https:\/\/www.wsisp.com\/helps\/37371.html","name":"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-15T14:28:03+00:00","dateModified":"2025-05-15T14:28:03+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/37371.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/37371.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/37371.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"spring\u4e2d\u7684@Async\u6ce8\u89e3\u8be6\u89e3"}]},{"@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\/37371","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=37371"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/37371\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/37370"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=37371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=37371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=37371"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=37371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}