느린 요청이있을 때 Android Volley 이중 게시
느린 네트워크에서 Volley POST 요청에 문제가 있습니다. BasicNetwork.logSlowRequests
LogCat에서 볼 때마다 POST 요청이 두 번 이상 실행되어 하나의 요청에 대해 여러 번 (2 개 이상) 게시됩니다. 이미 재시도 정책을 0으로 설정했지만 도움이되지 않습니다.
이것은 내 LogCat입니다
03-16 01 : 31 : 35.674 : D / Volley (5984) : [19807] BasicNetwork.logSlowRequests : 요청에 대한 HTTP 응답 = <[] http : // [myserver] / api / places 0xfa7d0c33 NORMAL 1> [lifetime = 3824 ], [size = 313], [rc = 200], [retryCount = 0] 03-16 01 : 31 : 35.704 : D / Volley (5984) : [1] Request.finish : 3853ms : [] http : / / [myserver] / api / places 0xfa7d0c33 정상 1
이것은 내 코드입니다
JSONObject body = new JSONObject();
try {
body.put(PROTO_BODY_AUTHORIZATION, Sessions.getActiveSession().getToken());
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.POST,
context.getResources().getString(R.string.server_address) + "/places",
body,
callback,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, error.getMessage(), Toast.LENGTH_LONG).show();
}
}
);
request.setRetryPolicy(
new DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
getRequestQueue().add(request);
이 문제에 대한 해결책을 필사적으로 찾고 있습니다.
Request 객체에 다음 값을 추가합니다.
request.setRetryPolicy(new DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
여기 : request는 JsonObjectRequest의 객체입니다. Volley의 DefaultRetryPolicy 클래스에서 DEFAULT TIMEOUT VALUE에 따라 multiplicator 값을 변경합니다.
다음과 같이 첫 번째 인수를 0으로 설정할 수도 있습니다.
request.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RetryPolicy에서 Timeout을 0으로 설정하는 것은 너무 적습니다. 소스를 확인한 후에는 현재 <= max ...를 확인하므로 실제로 최대 재시도 횟수를 <0으로 설정해야합니다.
정책을 다음과 같이 설정하여 이중 게시를 수정했습니다.
new DefaultRetryPolicy(0, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
도움이 되었기를 바랍니다.
이중 게시물에 대한 해결책을 찾았고 시간 제한을 0으로 설정했습니다.
다중 게시물 버그에 대한 해결책을 찾았습니다.
RetryPolicy를 변경하십시오. 제한 시간 값을 50000ms로 설정하고 다음과 같이 잘 작동했습니다.
request.setRetryPolicy(
new DefaultRetryPolicy(
500000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
)
);
RetryPolicy를 재시도 0으로 설정하고 제한 시간이 서버 제한 시간보다 큰지 확인해야합니다.
setRetryPolicy(new DefaultRetryPolicy("bigger than server timeout",
0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
이 문제를 두 가지 방법으로 해결할 수 있습니다.
First is changed the RetryPolicy
. Simply set the timeout value to double of the default timeout. Worked fine. You can also try other values.
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Another way is by setting connection.setChunkedStreamingMode(0);
in openConnection
method HurlStack
class.
I am creating my RequestQueue
like this requestQueue = Volley.newRequestQueue(context, new HurlStack());
Hope it helps :)
please increase the setRetryPolicy time.
request.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
Volley.newRequestQueue(this).add(equest);
This works for me.
public class MyRetryPolicyWithoutRetry implements RetryPolicy
{
@override
public int getCurrentTimeout()
{
return CONNECTION_TIME_OUT; /200000/
}
@Override
public int getCurrentRetryCount()
{
return 0;
}
@Override
public void retry(VolleyError error) throws VolleyError
{
throw(error);
}
}
To use:
request.setRetryPolicy(new MyRetryPolicyWithoutRetry());
I asked a similar question here:
Android Volley makes 2 requests to the server when retry policy is set to 0
I managed to solve this issue by setting the keep-alive property to false inside Android, e.g.:
System.setProperty("http.keepAlive", "false")
I added this line of code inside the class where I import requestqueue and make the requests.
Also, check if you server has the keep-alive header.
This post helped get to the solution.
I managed to fix this by configuring HttpURLConnection like this:
connection.setChunkedStreamingMode(0);
I started a discussion about this in Volley email list (https://groups.google.com/forum/#!topic/volley-users/8PE9dBbD6iA).
You can use this to solve the problem.
StringRequest.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
The only way I got the double requests to stop was to set the retry policy retries to -1
request.setRetryPolicy(new DefaultRetryPolicy(0, -1, 0));
I think this is because the DefaultRetryPolicy's logic for attempts remaining returns true if retryCount is 0 and Max retries is also 0 in the hasAttemptRemaining() method:
protected boolean hasAttemptRemaining() {
return this.mCurrentRetryCount <= this.mMaxNumRetries;
}
just maxNumRetries = 0
no work. set TIMEOUT_MS 20000
.
request.setRetryPolicy(new DefaultRetryPolicy(20000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 2, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
This worked for me.
correcting the android date
fixes my problem unfortunately for testing purpose i have changed my android date and get ssl security error.
Tried lot of things but in the end nothing helped. Finally, I figured out following combination of changes:
sr.setRetryPolicy(new DefaultRetryPolicy(0,-1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
And in your hurl connection in application class, add this:
httpsURLConnection.setChunkedStreamingMode(0);
This worked smoothly to stop Volley hitting multiple request at server.
ReferenceURL : https://stackoverflow.com/questions/22428343/android-volley-double-post-when-have-slow-request
'developer tip' 카테고리의 다른 글
특정 virtualenv에 설치된 패키지 목록을 어떻게 만들 수 있습니까? (0) | 2020.12.25 |
---|---|
Django Rest Framework : 개체 생성 후 필드 업데이트 비활성화 (0) | 2020.12.25 |
http.Request에서 클라이언트의 IP 주소를 가져 오는 올바른 방법 (0) | 2020.12.25 |
특정 색상을 생성하기 위해 필요한 색상 회전을 계산하는 방법은 무엇입니까? (0) | 2020.12.25 |
브라우저 창 중앙에 요소를 배치하는 방법은 무엇입니까? (0) | 2020.12.24 |