类内方法相互调用不会异步处理 @RequestMapping(value = "/totalQuery.json") public SearchResult totalQuery(){ System.out.println("totalQuery: " + Thread.currentThread().getId()); orderService.test(); return null; }
private static String string = "";
@Override @Async public void test() { test1(); string = string + "test:" + Thread.currentThread().getId(); System.out.println(string); } @Override @Async public void test1() { string = string + "test1:" + Thread.currentThread().getId(); System.out.println(string); }
打印结果,这是同一个线程id,所以没有用异步线程
test1:151
test1:151test:151
private static String string = ""; @Override // @Async public void test() { test1(); string = string + "test:" + Thread.currentThread().getId(); System.out.println(string); } @Override @Async public void test1() { string = string + "test1:" + Thread.currentThread().getId(); System.out.println(string); }
打印结果,这是同一个线程id,所以没有用异步线程
test1:111
test1:111test:111