我在控制器中有方法。我想从第一个方法调用同一个控制器中的另一个方法(两个都是RestAPI)但是它会生成
public Result make_something_easy(Long Id){
// Some easy code
Thread hard_independent_thread = new Thread() {
@Override
public void run() {
make_something_hard(object.id);
// no result required - just do that like void method
}
};
hard_independent_thread.start();
return ok(Json.toJson(object));
}
// You can call this on API separately
public Result make_something_hard(Long Id){
// Some code
// 30 second and more...
return ok();
}
但代码
make_something_hard(object.id);
发生此错误。我不知道为什么:
java.lang.RuntimeException: There is no HTTP Context available from here.
at play.mvc.Http$Context.current(Http.java:57)
at play.mvc.Controller.request(Controller.java:32)
at controllers.CompilationLibrariesController$1
.run(CompilationLibrariesController.java:360)