I'm building a Service to send data throught web services in Android using retrofit2.
Now this is the code:
private void checkUnsyncedRecords() {
        final DbLayer db = DatabaseHelper.getDatabase(getApplicationContext(), false);
        LinkedList<SensorData> listaDatiUnsunc = db.fetchSensorData(null, false);
        WebService webService = WebServiceHandler.getService();
        //endregion
        //region Alerts
        if (listaDatiUnsunc.size() > 0) {
            JsonArray readAlerts = new GsonBuilder().create().toJsonTree(listaDatiUnsunc).getAsJsonArray();
            //create request body
            JsonObject body = WebServiceHandler.getDefaultBody();
            body.addProperty(WebServiceHandler.ID_CLINICAL_DOCUMENT, 70);
            body.add(WebServiceHandler.VALORI, readAlerts);
            //Log.i(TAG, body.toString());
            try {
                Call<BaseMessage<JsonElement>> request = webService.insertDatiCalza(body);
                Response<BaseMessage<JsonElement>> response = request.execute();
                if (response.isSuccessful()) {
                    BaseMessage<JsonElement> message = response.body();
                    if (message != null) {
                        if (message.getStatus() == MessageStatus.SUCCESS) {
                            Log.d(TAG, "SensorValue sync succeeded");
                            //AGGIORNO LO STATO DI AGGIORNAMENTO DI TUTTE LE RILEVAZIONI
                            for (SensorData sens: listaDatiUnsunc) {
                                sens.setSync(true);
                                db.updateSensorData(sens);
                            }
                        } else {
                            Log.e(TAG, "SensorValue sync failed: " + message.getMessage() +
                                    " (code: " + message.getStatus() + ")");
                        }
                    } else {
                        Log.e(TAG, "SensorValue sync: reply message is null.");
                    }
                } else {
                    Log.e(TAG, "SensorValue sync: request failed (code: " +
                            response.code() + ", body: " + response.message() + ").");
                }
            } catch (Exception e) {
                Log.e(TAG, "SensorValue sync call", e);
            } finally {
            }
        }
        //endregion
    }
this code works, but sometimes the LinkedList contains more value and I have this exception if it size is big.
java.net.SocketTimeoutException
Now there is a way to increase the Timeout connection ?
EDIT This is the instance of my Retrofit class:
public static WebService getService() {
        if (webService == null) {
            Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();
            Retrofit retrofit = new Retrofit.Builder()
                    .addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(BASE_URL).build();
            webService = retrofit.create(WebService.class);
        }
        return webService;
    }
 
    