Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
RequestFuture.get(long timeout, Timeunit unit) not timing out

I'm having trouble using the Volley library. I don't want to wait for the request indefinitely, so I wan't to set a timeout. But it isn't working. I have the same thing in other places (where I use a RequestFuture and not a RequestFuture) and it's working fine, but in here I can't set it to work.

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

If you can provide any help it would be amazing! Thanks

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I was able to fix the issue!

The problem was that the server was answering with status code 204 (NO_CONTENT) and it wasn't sending any content.

The most likely explanation is that because a success status code is being returned (2XX), it waits indefinitely for a JSONObject that never comes, ignoring the timeout (because it received a success code).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda