Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring MVC中异步数据访问的全局变量_Java_Spring_Spring Mvc - Fatal编程技术网

Java spring MVC中异步数据访问的全局变量

Java spring MVC中异步数据访问的全局变量,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个控制器 @Controller public class TestController{ public Future<ArrayList<String>> global_value = null; @Autowired private AsyncService asyncService; @RequestMapping(value = "/asyncCall", method = RequestMethod.GET, produces = MediaType

我有一个控制器

@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;
}

}
@控制器
公共类测试控制器{
公共未来全局_值=空;
@自动连线
专用异步服务;
@RequestMapping(value=“/asyncCall”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u value)
@应答器
公共字符串getToken(HttpServletRequest请求){
全局_值=asyncService.execute();
返回“OK”;
}
@RequestMapping(value=“/getAsyncData”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u value)
@应答器
公共ArrayList getData(){
试一试{
if(global_value!=null&&global_value.get().size()>0){
返回全局_值。get();
}
}捕捉(中断异常e){
e、 printStackTrace();
}捕获(执行例外){
e、 printStackTrace();
}
返回null;
}
}
当我长时间轮询
getAsncData
端点时,如何维护仅针对请求的全局_值。全局_值对于请求范围必须是唯一的


如何实现这一点?

如果您希望在请求范围中使用全局值,则不要将其作为实例变量。您的意思是将其定义为静态?