Home >Java >javaTutorial >Can Volley Perform Synchronous Network Requests in a Background Thread?
Synchronous Network Requests using Volley
Q: Can I perform synchronous network requests in a background thread using Volley?
Reasoning:
A: Yes, it's possible with Volley's RequestFuture class.
For instance, to make a synchronous JSON GET request:
RequestFuture<JSONObject> future = RequestFuture.newFuture(); JsonObjectRequest request = new JsonObjectRequest(URL, new JSONObject(), future, future); requestQueue.add(request); try { JSONObject response = future.get(); // this will block } catch (InterruptedException | ExecutionException e) { // Exception handling }
The above is the detailed content of Can Volley Perform Synchronous Network Requests in a Background Thread?. For more information, please follow other related articles on the PHP Chinese website!