第一种情况,Service类:
@Async public String test1() { String threadName = Thread.currentThread().getName(); log.error("{}: 1 start", threadName); try { Thread.sleep(5000L); } catch (Exception e){ } log.error("{}: 1 end", threadName); return "s1"; } @Async public String test2() { String threadName = Thread.currentThread().getName(); log.error("{}: 2 start", threadName); try { Thread.sleep(2000L); } catch (Exception e){ } log.error("{}: 2 end", threadName); return "s2"; }
Controller类:
try { String threadName = Thread.currentThread().getName(); log.error("{}: 0 start", threadName); PrintWriter out = response.getWriter(); String f1 = testService.test1();