Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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 RequestFuture.get(长超时,时间单位)未超时_Java_Android_Android Volley_Java Threads - Fatal编程技术网

Java RequestFuture.get(长超时,时间单位)未超时

Java RequestFuture.get(长超时,时间单位)未超时,java,android,android-volley,java-threads,Java,Android,Android Volley,Java Threads,我无法使用截击库。我不想无限期地等待请求,所以我不想设置超时。但它不起作用。我在其他地方也有同样的东西(我使用RequestFuture而不是RequestFuture),它工作得很好,但在这里我无法设置它工作 static final long TIMEOUT = 3; static final TimeUnit TIMEOUT_TIME_UNIT = TimeUnit.SECONDS; public boolean fetchPoiUserRating(PoiModel poi, Strin

我无法使用截击库。我不想无限期地等待请求,所以我不想设置超时。但它不起作用。我在其他地方也有同样的东西(我使用RequestFuture而不是RequestFuture),它工作得很好,但在这里我无法设置它工作

static final long TIMEOUT = 3;
static final TimeUnit TIMEOUT_TIME_UNIT = TimeUnit.SECONDS;
public boolean fetchPoiUserRating(PoiModel poi, String userId) throws RemoteDataException {
    RequestQueue queue = mRequestQueue;

    String url = API_POI_RATING_URL + "/" + poi.getId() + "/" + userId;

    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, future, future);
    future.setRequest(queue.add(request));

    try {
        Log.d(TAG, "Start poi user rating fetch");
        JSONObject response = future.get(TIMEOUT, TIMEOUT_TIME_UNIT); // this should timeout but it doesn't
        Log.d(TAG, "Finished poi user rating fetch");
        poi.setUserRating((float) response.getDouble("rating"));
        return true;
    } catch (InterruptedException | ExecutionException | JSONException | TimeoutException e) {
        handleError(e);
        return false;
    }
}
静态最终长超时=3;
静态最终时间单位超时时间单位=TimeUnit.SECONDS;
公共布尔fetchPoiUserRating(PoiModel poi,字符串userId)引发RemoteDataException{
RequestQueue=mRequestQueue;
字符串url=API_POI_RATING_url+“/”+POI.getId()+“/”+userId;
RequestFuture=RequestFuture.newFuture();
JsonObjectRequest=newJSONObjectRequest(request.Method.GET,url,null,future,future);
future.setRequest(queue.add(request));
试一试{
Log.d(标签,“开始poi用户评级获取”);
JSONObject response=future.get(TIMEOUT,TIMEOUT\u TIME\u UNIT);//这应该超时,但不会超时
Log.d(标记“完成poi用户评级获取”);
poi.setUserRating((float)response.getDouble(“rating”);
返回true;
}捕获(InterruptedException | ExecutionException | JSONException | TimeoutException e){
handleError(e);
返回false;
}
}

如果你能提供任何帮助,那就太棒了!谢谢

我解决了这个问题

问题是服务器正在应答状态代码204(无内容),并且没有发送任何内容

最可能的解释是,由于返回了一个成功状态代码(2XX),它会无限期地等待一个永远不会出现的JSONObject,忽略超时(因为它收到了一个成功代码)。

它所说的(我使用的是RequestFuture而不是RequestFuture)应该是(我使用的是RequestFuture而不是RequestFuture)。另外,我忘了提及,但这是在后台线程上运行的