Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xzxt-api-report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
雷紫添
xzxt-api-report
Commits
f64a456f
Commit
f64a456f
authored
Jan 18, 2022
by
wang_jiaxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将线程数量控制放在配置文件中,增加集群配置
parent
50b1821e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
10 deletions
+48
-10
src/main/java/com/founder/file/service/impl/XjFlwsServiceImpl.java
+44
-10
src/main/resources/application-dev.yml
+4
-0
No files found.
src/main/java/com/founder/file/service/impl/XjFlwsServiceImpl.java
View file @
f64a456f
...
...
@@ -5,12 +5,15 @@ import com.founder.file.service.XjFlwsService;
import
com.founder.util.HttpUtil
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.FutureTask
;
@Service
...
...
@@ -18,20 +21,51 @@ public class XjFlwsServiceImpl implements XjFlwsService {
@Autowired
private
XjxzFlwsMapper
xjxzFlwsMapper
;
@Value
(
"${poorSize}"
)
private
Integer
poorSize
;
@Value
(
"${clusterSize}"
)
private
Integer
clusterSize
;
@Value
(
"${clusterId}"
)
private
Integer
clusterId
;
private
final
ExecutorService
cachedThreadPool
;
{
cachedThreadPool
=
Executors
.
newCachedThreadPool
();
}
@Override
public
String
getJzzjkFlwsnrToXjxz
(
Date
date
,
String
xxzjbh
)
throws
IOException
{
if
(
clusterId
>
clusterSize
){
return
"集群数量有误,集群id不能大于集群数量!"
;
}
Integer
count
=
xjxzFlwsMapper
.
getFlwsCountWzByDate
(
date
,
xxzjbh
);
int
page
=
(
count
/
1000
)
+
1
;
ArrayList
<
FutureTask
<
Map
<
String
,
Integer
>>>
list
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
page
;
i
++)
{
int
limit
=
1000
;
int
begin
=
i
*
limit
;
int
end
=
(
i
+
1
)
*
limit
;
int
finalI
=
i
;
int
lmt
=
count
/
clusterSize
;
int
remainder
=
count
%
clusterSize
;
if
(
clusterId
<=
remainder
)
{
lmt
++;
}
int
cou
=
lmt
/
poorSize
;
int
remainderCou
=
lmt
%
poorSize
;
int
begin
=
(
clusterId
-
1
)
*
lmt
;
if
(
remainder
>
0
&&
clusterId
>
remainder
)
{
begin
=
begin
+
remainder
;
}
int
end
;
for
(
int
i
=
0
;
i
<
poorSize
;
i
++)
{
int
finalBegin
=
begin
;
end
=
begin
+
cou
;
if
(
i
<
remainderCou
)
{
end
++;
}
begin
=
end
;
int
finalEnd
=
end
;
FutureTask
<
Map
<
String
,
Integer
>>
xsAjTask
=
new
FutureTask
<>(()
->
{
HashMap
<
String
,
Integer
>
map
=
new
HashMap
<>();
List
<
Map
<
String
,
String
>>
flwsList
=
xjxzFlwsMapper
.
getFlwsWzByDate
(
date
,
xxzjbh
,
begin
,
e
nd
);
List
<
Map
<
String
,
String
>>
flwsList
=
xjxzFlwsMapper
.
getFlwsWzByDate
(
date
,
xxzjbh
,
finalBegin
,
finalE
nd
);
ArrayList
<
Exception
>
exceptions
=
new
ArrayList
<>();
System
.
out
.
println
(
"+++++++++++++"
+
flwsList
.
size
());
int
j
=
1
;
...
...
@@ -40,7 +74,7 @@ public class XjFlwsServiceImpl implements XjFlwsService {
for
(
Map
<
String
,
String
>
flws
:
flwsList
)
{
try
{
String
flwsUrl
=
flws
.
get
(
"FWDZ"
)
+
flws
.
get
(
"TXLJ"
);
System
.
out
.
println
(
flwsUrl
);
//
System.out.println(flwsUrl);
InputStream
is
=
HttpUtil
.
getInputStreamByUrl
(
flwsUrl
);
if
(
is
!=
null
)
{
byte
[]
bytes
=
IOUtils
.
toByteArray
(
is
);
...
...
@@ -62,7 +96,7 @@ public class XjFlwsServiceImpl implements XjFlwsService {
e
.
printStackTrace
();
exceptions
.
add
(
e
);
}
System
.
out
.
println
(
"线程"
+
finalI
+
"++++++++++++++"
+
(
j
++));
System
.
out
.
println
(
"线程"
+
Thread
.
currentThread
().
getName
()
+
"++++++++++++++"
+
(
j
++));
}
map
.
put
(
"exceptions"
,
exceptions
.
size
());
map
.
put
(
"flws"
,
flwsCount
);
...
...
@@ -70,7 +104,7 @@ public class XjFlwsServiceImpl implements XjFlwsService {
System
.
out
.
println
(
"============="
+
exceptions
.
size
());
return
map
;
});
new
Thread
(
xsAjTask
).
start
(
);
cachedThreadPool
.
submit
(
xsAjTask
);
list
.
add
(
xsAjTask
);
}
int
flsws
=
0
;
...
...
src/main/resources/application-dev.yml
View file @
f64a456f
...
...
@@ -35,6 +35,10 @@ spring:
poorSize
:
1000
clusterSize
:
1
clusterId
:
1
ftpserverip
:
47.92.129.99
nginxport
:
9053
ftpport
:
4546
...
...
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