Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!