↗ JetBrains 20% discount
Buy any product from JetBrains and get a 20% discount.
Spring MVC
WebAsyncTask can be used to wrap a callable to customize asynchronous processing.
package com.logicbig.example;import jakarta.servlet.http.HttpServletRequest;import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.context.request.async.WebAsyncTask;import java.util.concurrent.Callable;import java.util.concurrent.Executors;@Controllerpublic class MyWebController3 { @GetMapping("/test3") @ResponseBody public WebAsyncTask<String> handleRequest(HttpServletRequest r) { System.out.println("asyncSupported: " + r.isAsyncSupported()); System.out.println(Thread.currentThread().getName()); Callable<String> callable = () -> { System.out.println(Thread.currentThread().getName()); return "WebAsyncTask test"; }; ConcurrentTaskExecutor t = new ConcurrentTaskExecutor( Executors.newFixedThreadPool(1)); return new WebAsyncTask<>(10000L, t, callable); }}