Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-trialdrive-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6e40f2f0
authored
Mar 26, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
jetty性能调优,下载优化
1 parent
f0481eb9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
9 deletions
src/main/java/cn/com/glsx/admin/config/JettyConfig.java
src/main/java/cn/com/glsx/admin/modules/service/WorkOrderService.java
src/main/java/cn/com/glsx/admin/config/JettyConfig.java
0 → 100644
View file @
6e40f2f
package
cn
.
com
.
glsx
.
admin
.
config
;
import
org.eclipse.jetty.server.Server
;
import
org.eclipse.jetty.server.ServerConnector
;
import
org.eclipse.jetty.util.thread.QueuedThreadPool
;
import
org.springframework.boot.web.embedded.jetty.JettyServerCustomizer
;
import
org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
JettyConfig
{
@Bean
public
JettyServletWebServerFactory
jettyEmbeddedServletContainerFactory
(
JettyServerCustomizer
jettyServerCustomizer
)
{
JettyServletWebServerFactory
factory
=
new
JettyServletWebServerFactory
();
factory
.
addServerCustomizers
(
jettyServerCustomizer
);
return
factory
;
}
@Bean
public
JettyServerCustomizer
jettyServerCustomizer
()
{
return
server
->
{
configJettyServer
(
server
);
threadPool
(
server
);
};
}
public
void
configJettyServer
(
Server
server
)
{
ServerConnector
connector
=
server
.
getBean
(
ServerConnector
.
class
);
connector
.
setIdleTimeout
(
1800000
);
}
public
void
threadPool
(
Server
server
)
{
// Tweak the connection config used by Jetty to handle incoming HTTP
// connections
final
QueuedThreadPool
threadPool
=
server
.
getBean
(
QueuedThreadPool
.
class
);
//默认最大线程连接数200
threadPool
.
setMaxThreads
(
200
);
//默认最小线程连接数8
threadPool
.
setMinThreads
(
20
);
//默认线程最大空闲时间60000ms
threadPool
.
setIdleTimeout
(
1800000
);
}
}
src/main/java/cn/com/glsx/admin/modules/service/WorkOrderService.java
View file @
6e40f2f
...
@@ -44,6 +44,7 @@ import org.springframework.beans.BeanUtils;
...
@@ -44,6 +44,7 @@ import org.springframework.beans.BeanUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.StopWatch
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -141,6 +142,8 @@ public class WorkOrderService {
...
@@ -141,6 +142,8 @@ public class WorkOrderService {
}
}
public
void
batchExportPics
(
HttpServletResponse
response
,
WorkOrderSearch
search
)
throws
IOException
{
public
void
batchExportPics
(
HttpServletResponse
response
,
WorkOrderSearch
search
)
throws
IOException
{
StopWatch
sw
=
new
StopWatch
();
sw
.
start
(
"生成Zip文件task1"
);
List
<
WorkOrderDocs
>
docsList
=
workOrderDocsMapper
.
selectByOrderIds
(
search
.
getOrderIds
());
List
<
WorkOrderDocs
>
docsList
=
workOrderDocsMapper
.
selectByOrderIds
(
search
.
getOrderIds
());
Map
<
Long
,
List
<
WorkOrderDocs
>>
docsMap
=
docsList
.
parallelStream
().
collect
(
Collectors
.
groupingBy
(
WorkOrderDocs:
:
getWorkOrderId
));
Map
<
Long
,
List
<
WorkOrderDocs
>>
docsMap
=
docsList
.
parallelStream
().
collect
(
Collectors
.
groupingBy
(
WorkOrderDocs:
:
getWorkOrderId
));
...
@@ -149,18 +152,17 @@ public class WorkOrderService {
...
@@ -149,18 +152,17 @@ public class WorkOrderService {
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
final
ZipOutputStream
out
=
new
ZipOutputStream
(
baos
);
final
ZipOutputStream
z
out
=
new
ZipOutputStream
(
baos
);
for
(
WorkOrderVehicle
wv
:
wvList
)
{
for
(
WorkOrderVehicle
wv
:
wvList
)
{
List
<
WorkOrderDocs
>
woDocs
=
docsMap
.
get
(
wv
.
getWorkOrderId
());
List
<
WorkOrderDocs
>
woDocs
=
docsMap
.
get
(
wv
.
getWorkOrderId
());
String
vinPath
=
wv
.
getVin
()
+
File
.
separator
;
ZipEntry
vinDir
=
new
ZipEntry
(
vinPath
);
if
(
CollectionUtils
.
isNotEmpty
(
woDocs
))
{
if
(
CollectionUtils
.
isNotEmpty
(
woDocs
))
{
//车架号目录
//车架号目录
out
.
putNextEntry
(
vinDir
);
String
vinPath
=
wv
.
getVin
()
+
File
.
separator
;
zout
.
putNextEntry
(
new
ZipEntry
(
vinPath
));
zout
.
closeEntry
();
for
(
WorkOrderDocs
doc
:
woDocs
)
{
for
(
WorkOrderDocs
doc
:
woDocs
)
{
byte
[]
bytes
=
HttpUtils
.
downloadBytes
(
doc
.
getPath
());
byte
[]
bytes
=
HttpUtils
.
downloadBytes
(
doc
.
getPath
());
String
filename
=
doc
.
getName
();
String
filename
=
doc
.
getName
();
...
@@ -172,19 +174,25 @@ public class WorkOrderService {
...
@@ -172,19 +174,25 @@ public class WorkOrderService {
filename
=
filename
+
suffix
;
filename
=
filename
+
suffix
;
}
}
}
}
out
.
putNextEntry
(
new
ZipEntry
(
vinPath
+
filename
));
zout
.
putNextEntry
(
new
ZipEntry
(
vinPath
+
filename
));
out
.
write
(
bytes
,
0
,
bytes
.
length
);
zout
.
write
(
bytes
,
0
,
bytes
.
length
);
zout
.
closeEntry
();
}
}
}
}
}
}
out
.
close
();
zout
.
close
();
sw
.
stop
();
sw
.
start
(
"下载Zip文件task2"
);
String
filename
=
new
String
(
DateUtils
.
formatSerial
(
new
Date
()).
getBytes
(
StandardCharsets
.
UTF_8
),
StandardCharsets
.
ISO_8859_1
)
+
".zip"
;
String
filename
=
new
String
(
DateUtils
.
formatSerial
(
new
Date
()).
getBytes
(
StandardCharsets
.
UTF_8
),
StandardCharsets
.
ISO_8859_1
)
+
".zip"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
filename
+
"\""
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
filename
+
"\""
);
response
.
setHeader
(
"Content-Type"
,
"application/zip"
);
response
.
setHeader
(
"Content-Type"
,
"application/zip"
);
response
.
getOutputStream
().
write
(
baos
.
toByteArray
());
response
.
getOutputStream
().
write
(
baos
.
toByteArray
());
response
.
flushBuffer
();
response
.
flushBuffer
();
baos
.
close
();
baos
.
close
();
sw
.
stop
();
log
.
info
(
"批量下载工单图片任务耗时概览:{},总耗时:{}秒"
,
sw
.
prettyPrint
(),
sw
.
getTotalTimeSeconds
());
}
}
public
List
<
WorkOrderImport
>
batchImport
(
List
<
WorkOrderImport
>
importList
)
{
public
List
<
WorkOrderImport
>
batchImport
(
List
<
WorkOrderImport
>
importList
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment