Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yangyoupeng
/
zhaoonline-utils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yangyoupeng
2016-10-25 17:42:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3abc10255007215ab6f80bef1f044c2e9ee12f8b
3abc1025
1 parent
00976395
添加ESHttpClient.queryAll方法中死循环保护方法
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletions
src/main/java/com/zhaoonline/common/es/ESHttpClient.java
src/main/java/com/zhaoonline/common/es/ESHttpClient.java
View file @
3abc102
...
...
@@ -177,12 +177,19 @@ public class ESHttpClient {
QueryResponse
returnResponse
=
new
QueryResponse
();
int
size
=
queryBuilder
.
getPage
().
getSize
();
if
(
size
==
0
){
return
null
;
}
LoopCount
loopcount
=
null
;
boolean
readDone
=
false
;
while
(!
readDone
){
QueryResponse
queryResponse
=
this
.
query
(
queryBuilder
);
int
totalSize
=
queryResponse
.
getTotal
().
intValue
();
int
returnDataSize
=
queryResponse
.
getDataList
().
size
();
returnResponse
.
addData
(
queryResponse
.
getDataList
());
int
alreadyReadSize
=
queryBuilder
.
getPage
().
getStart
()+
returnDataSize
;
if
(
alreadyReadSize
>=
totalSize
){
...
...
@@ -190,12 +197,24 @@ public class ESHttpClient {
returnResponse
.
setTotal
(
new
Long
(
totalSize
));
break
;
}
//为了防止异常的出现死循环
if
(
loopcount
==
null
){
loopcount
=
new
LoopCount
();
loopcount
.
maxLoopcount
=
totalSize
/
size
;
}
else
if
(
loopcount
.
maxLoopcount
<=
0
){
break
;
}
else
{
loopcount
.
maxLoopcount
=
loopcount
.
maxLoopcount
-
1
;
}
queryBuilder
.
setPage
(
alreadyReadSize
,
size
);
}
return
returnResponse
;
}
private
class
LoopCount
{
int
maxLoopcount
=
0
;
}
/**
...
...
Please
register
or
login
to post a comment