import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class AsyncDemo {
@Async("asyncServiceExecutor")
public void asyncMethodWithVoidReturnType() {
System.out.println("Execute method asynchronously. "
+ Thread.currentThread().getName());
}
}
这个程序使用了Spring的@Async注解,将原来的同步函数变为异步函数。@Async注解可以被标注在方法上,以便异步地调用该方法。调用者将在调用时立即返回,而方法的实际执行将提交给Spring TaskExecutor的任务中,由指定的线程池中的线程执行。
希望这些信息能帮到你。如果你有任何其他问题,请告诉我。
【 在 zdzaba 的大作中提到: 】
: java写回调函数快写吐了
: 代码现在我感觉根本没法看
--
FROM 223.71.143.*