前台代码:
$(function(){
function poll(){
var param={“searchType”:”1″,”key”:”0100008″,”timestamp”:”1409382910″ ,”sign”:”123″ };
$.ajax({ type: “POST”,
contentType:”application/json;charset=utf-8″,
url: “xxxx”,data:JSON.stringify(param), success:function(data) {
console.log(data);
poll();
}, dataType: “json” });
}
poll();
});
后台代码:
private final ExecutorService exec = Executors.newFixedThreadPool(1);
private BlockingQueue queue=new ArrayBlockingQueue<>(5);
@RequestMapping(value = “/findUserAreaList3”)
@ResponseBody
public BaseResult findUserAreaList3() {
Callable call = new Callable() {
public Object call() throws Exception {
Object take = queue.take();
return take;
}
};
Future future = exec.submit(call);
Object ret;
try {
// 任务处理超时时间设为 10秒
ret = future.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
return setResponseVo(“error”);
}
return setResponseVo(ret);
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183345.html原文链接:https://javaforall.cn