Я пытаюсь сделать синхронный запрос, используя залп, чтобы я мог вернуть placeid
, который возвращается из mySQL. Но я получаю TimeoutException
, и я не знаю, как это исправить.
Это мой журнал:
I / VOLLEY: запрос добавлен
I / VOLLEY: log3java.util.concurrent.TimeoutException
Я / Хореограф: пропущено 59 кадров! Приложение может выполнять слишком много работы в своем основном потоке.
V / FA: запись участия пользователя, мс: 102327
V / FA: подключение к удаленному сервису
V / FA: активность приостановлена, время: 1669661030
D / FA: регистрация событий (FE): user_engagement (_e), Bundle [{firebase_event_origin (_o) = auto, engagement_time_msec (_et) = 102327, firebase_screen_class (_sc) = CreatePlace2, firebase_screen_id (_si223) = 2800180808068686868
V / FA: попытка подключения уже выполняется
D / FA: подключено к удаленному сервису
V / FA: Обработка поставленных в очередь сервисных задач: 2
V / FA: бездействие, отключение от службы
а это мой код:
public JSONObject createPlaces(final String PlaceName, final int PlaceCategory, final Double PlaceLatitude
, final Double PlaceLongitude, final String NpcId) {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Constants.URL_PLACES_CREATE, new JSONObject(),
future,future) {
@Override
protected Map<String, String> getParams () throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("placename", PlaceName);
params.put("categoryid", String.valueOf(PlaceCategory));
params.put("placelat", String.valueOf(PlaceLatitude));
params.put("placelng", String.valueOf(PlaceLongitude));
params.put("npcid", String.valueOf(NpcId));
return params;
}
};
RequestHandler.getInstance(mCtx).addToRequestQueue(request);
Log.i("VOLLEY","request added");
try {
JSONObject response = future.get(1, TimeUnit.SECONDS); // this will block
Log.i("VOLLEY","log"+response);
return response;
} catch (InterruptedException e) {
// exception handling
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log1"+e);
} catch (ExecutionException e) {
// exception handling
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log2"+e);
} catch (TimeoutException e) {
future.onErrorResponse(new VolleyError(e));
Log.i("VOLLEY","log3"+e);
}
return null;
}