Spring启用异步执行任务

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# async executor
async:
corePoolSize: 20
maxPoolSize: 200
queueCapacity: 10000
# async executor async: corePoolSize: 20 maxPoolSize: 200 queueCapacity: 10000
# async executor
async:
    corePoolSize: 20
    maxPoolSize: 200
    queueCapacity: 10000

然后代码中注入

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@Autowired
private SpringAsyncExecutor asyncExecutor;
@Autowired private SpringAsyncExecutor asyncExecutor;
@Autowired
private SpringAsyncExecutor asyncExecutor;

使用

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Future<Map<Integer, String>> xxxFuture =
asyncExecutor.async(() -> xxxCall);
Future<Map<Integer, String>> xxxFuture = asyncExecutor.async(() -> xxxCall);
Future<Map<Integer, String>> xxxFuture =
                asyncExecutor.async(() -> xxxCall);

 

Leave a Reply

Your email address will not be published. Required fields are marked *