Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
e2e93b03
Commit
e2e93b03
authored
Nov 15, 2018
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
耗时统计, 看看哪里满了.
parent
0ca907cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
SyncHashController.java
...antgroup/xyqb/controller/external/SyncHashController.java
+9
-1
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/SyncHashController.java
View file @
e2e93b03
...
@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
...
@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.entity.UserHashMapping;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.repository.IUserRepository
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
cn.quantgroup.xyqb.util.encrypt.MD5Util
;
import
com.google.common.base.Stopwatch
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.BatchPreparedStatementSetter
;
import
org.springframework.jdbc.core.BatchPreparedStatementSetter
;
...
@@ -19,6 +20,7 @@ import java.util.ArrayList;
...
@@ -19,6 +20,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
@Slf4j
@Slf4j
@RestController
@RestController
...
@@ -50,12 +52,15 @@ public class SyncHashController {
...
@@ -50,12 +52,15 @@ public class SyncHashController {
.
execute
(()
->
{
.
execute
(()
->
{
Long
startPosition
=
startUserId
;
Long
startPosition
=
startUserId
;
while
(
isContinue
)
{
while
(
isContinue
)
{
Stopwatch
started
=
Stopwatch
.
createStarted
();
Long
endPosition
=
startPosition
+
step
;
Long
endPosition
=
startPosition
+
step
;
List
<
User
>
users
=
userRepository
.
findByIdBetween
(
startPosition
,
endPosition
);
List
<
User
>
users
=
userRepository
.
findByIdBetween
(
startPosition
,
endPosition
);
if
(
users
.
isEmpty
())
{
if
(
users
.
isEmpty
())
{
log
.
info
(
"没有数据了. 结束了"
);
log
.
info
(
"没有数据了. 结束了"
);
return
;
return
;
}
}
log
.
info
(
"查询用户需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
started
=
started
.
reset
().
start
();
List
<
UserHashMapping
>
userHashMappings
=
new
ArrayList
<>();
List
<
UserHashMapping
>
userHashMappings
=
new
ArrayList
<>();
users
.
forEach
(
user
->
{
users
.
forEach
(
user
->
{
UserHashMapping
userHashMapping
=
new
UserHashMapping
();
UserHashMapping
userHashMapping
=
new
UserHashMapping
();
...
@@ -63,7 +68,8 @@ public class SyncHashController {
...
@@ -63,7 +68,8 @@ public class SyncHashController {
userHashMapping
.
setPhoneNoMd5
(
MD5Util
.
build
(
user
.
getPhoneNo
()));
userHashMapping
.
setPhoneNoMd5
(
MD5Util
.
build
(
user
.
getPhoneNo
()));
userHashMappings
.
add
(
userHashMapping
);
userHashMappings
.
add
(
userHashMapping
);
});
});
log
.
info
(
"遍历计算md5&crc32需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
started
=
started
.
reset
().
start
();
String
sql
=
"INSERT INTO `user_hash_mapping` ( `user_id`, `phone_no_md5`, `phone_no_md5_short`) VALUES (?,?,?);"
;
String
sql
=
"INSERT INTO `user_hash_mapping` ( `user_id`, `phone_no_md5`, `phone_no_md5_short`) VALUES (?,?,?);"
;
jdbcTemplate
.
batchUpdate
(
sql
,
new
BatchPreparedStatementSetter
()
{
jdbcTemplate
.
batchUpdate
(
sql
,
new
BatchPreparedStatementSetter
()
{
@Override
@Override
...
@@ -80,6 +86,8 @@ public class SyncHashController {
...
@@ -80,6 +86,8 @@ public class SyncHashController {
}
}
});
});
log
.
info
(
"batchUpdate需要的时间 : {}ms"
,
started
.
elapsed
(
TimeUnit
.
MILLISECONDS
));
log
.
info
(
"来一波,start:{},end:{}"
,
startPosition
,
endPosition
);
log
.
info
(
"来一波,start:{},end:{}"
,
startPosition
,
endPosition
);
startPosition
=
users
.
get
(
users
.
size
()
-
1
).
getId
()
+
1
;
startPosition
=
users
.
get
(
users
.
size
()
-
1
).
getId
()
+
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment