我使用下面的代码使用Okhttp 3.8.1进行一次休息电话。每两天应用程序因套接字关闭错误而崩溃
def get_monthly_mean(df):
avg_by_month = []
months = ['Jan', 'Feb', 'Mar', 'Apr', 'June', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
for i in range(11):
x = np.mean(df['CallsPresented'][df.loc[df['Month_of_Year'] == months[i]]])
avg_by_month.append(x)
return months
应用程序每两天崩溃,套接字超时套接字关闭异常指向行
@Override
public void doExecute(String url, String method, HttpHeaderBuilder headerBuilder, HttpRequestContext requestContext, GeneralRequestListener callback) {
OkHttpClient client = new OkHttpClient();
String webServiceEndPoint = url;
Response response =null;
if (!url.matches("^(http|https)://.*$")) {
webServiceEndPoint = backendConfig.getWebServiceUri().concat(url);
}
Request request = new Request.Builder()
.url(webServiceEndPoint)
.method(method, getRequestBody(requestContext, method))
.headers(buildHeaders(headerBuilder))
.build();
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
if (isJsonObject(responseBody)) {
callback.onSuccess(JsonObjectBuilder.fromString(responseBody));
} else if (isJsonArray(responseBody)) {
callback.onSuccess(JsonObjectBuilder.arrayfromString(responseBody));
} else {
// logger.debug("couldn't determine response type [response : {}]", responseBody);
callback.onSuccess(responseBody);
}
} else {
callback.onError(responseBody, new SimpleStatusLine(response.code(), ""));
}
if(response!=null)response.close();
} catch (Exception e) {
callback.onFailure(e);
if(response!=null)response.close();
}
}
即使我关闭了答复,为什么我仍然看到此问题?另外,当我在应用程序监视中看到时,我看到OkHttp连接不断增加。任何线索可能导致此问题?