@IocBean(args = {"appid String"})
public class TestAsyncService {
private String appid;
public TestAsyncService(String appid) {
System.out.println(appid + "-------1------");
this.appid = appid;
}
@Async
public void test(){
try {
Thread.sleep(5000);
System.out.println(appid + "-------2------");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@IocBean
@At("/test")
public class TestAction {
@Inject(":see hi")
TestAsyncService service;
@At("")
public void index(){
long time1 = new Date().getTime();
System.out.println("这是进入前");
service.test();
long time2 = new Date().getTime();
System.out.println("这是进入后,时间差=" + (time2-time1));
}
}
打印结果:
see hi-------1------
这是进入前
see hi-------2------
这是进入后,时间差=5001
@wendal 大佬 我这是不是哪里写的有问题才会导致出现这个问题呀