我有一个以下控制器
@Controller
public class TestController{
public Future<ArrayList<String>> global_value = null;
@Autowired
private AsyncService asyncService;
@RequestMapping(value = "/asyncCall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String getToken(HttpServletRequest request) {
global_value = asyncService.execute();
return "OK";
}
@RequestMapping(value = "/getAsyncData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ArrayList<String> getData() {
try {
if (global_value != null && global_value.get().size() > 0) {
return global_value.get();
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
}
当我长时间轮询getAsncData
端点时,如何维护global_value仅用于请求。 global_value对于请求范围必须是唯一的。
我怎样才能做到这一点?