Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
haoban3.0
haoban-manage3.0
Commits
ef622d52
Commit
ef622d52
authored
Oct 29, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log
parent
1b2ae7d6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
17 deletions
+25
-17
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+3
-0
MaterialApiServiceImpl.java
...nage/service/service/out/impl/MaterialApiServiceImpl.java
+1
-0
QWmediaTest.java
haoban-manage3-service/src/test/java/QWmediaTest.java
+21
-17
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
ef622d52
...
...
@@ -83,8 +83,11 @@ public class ImageCombined {
}
//压缩图片的参数
imageUrl
=
imageUrl
+
"?imageView2/2/w/1080/h/10800/format/jpg"
;
logger
.
info
(
"加载要合成的图片开始1"
);
BufferedImage
largeImage
=
loadImageWithCache
(
imageUrl
);
logger
.
info
(
"加载要合成的图片开始2"
);
BufferedImage
qrCodeImage
=
loadImageWithReader
(
qrCodeUrl
);
logger
.
info
(
"加载要合成的图片结束"
);
if
(
largeImage
==
null
||
qrCodeImage
==
null
)
{
return
null
;
}
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/MaterialApiServiceImpl.java
View file @
ef622d52
...
...
@@ -534,6 +534,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
try
{
future
=
ImageCombined
.
EXECUTOR
.
submit
(()
->
{
TraceIdUtil
.
traceBegin
(
TraceIdUtil
.
EntranceType
.
QUARTZ
);
logger
.
info
(
"线程池合成图片"
);
JSONResponse
jr
=
materialService
.
getMaterialIdByCombined
(
wxEnterpriseId
,
combinedQDTO
);
TraceIdUtil
.
traceEnd
();
return
jr
;
...
...
haoban-manage3-service/src/test/java/QWmediaTest.java
View file @
ef622d52
...
...
@@ -19,9 +19,7 @@ import org.springframework.test.context.ContextConfiguration;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.List
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.*
;
import
java.util.concurrent.atomic.AtomicLong
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
...
...
@@ -65,45 +63,51 @@ public class QWmediaTest {
jo
.
put
(
"lineTwo"
,
"宇智222为您推荐"
);
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
50
);
// 创建线程池
CountDownLatch
latch
=
new
CountDownLatch
(
TOTAL_REQUESTS
);
// 创建CountDownLatch,初始值为请求总数
Semaphore
semaphore
=
new
Semaphore
(
50
);
// 限制并发请求数为50
// 用于统计请求耗时
// 用于统计请求耗时
AtomicLong
totalTime
=
new
AtomicLong
(
0
);
AtomicLong
maxTime
=
new
AtomicLong
(
0
);
AtomicLong
minTime
=
new
AtomicLong
(
Long
.
MAX_VALUE
);
for
(
int
i
=
0
;
i
<
list
.
size
()
;
i
++)
{
for
(
int
i
=
0
;
i
<
TOTAL_REQUESTS
;
i
++)
{
final
int
requestId
=
i
;
executorService
.
submit
(()
->
{
long
startTime
=
System
.
currentTimeMillis
();
try
{
semaphore
.
acquire
();
// 获取许可,控制并发请求
jo
.
put
(
"imageUrl"
,
list
.
get
(
requestId
));
String
post
=
HttpUtil
.
post
(
"https://www.gicdev.com/haoban-manage3-wx/combined-qw-materialid.json"
,
jo
.
toJSONString
());
System
.
out
.
println
(
post
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"异常
"
);
System
.
out
.
println
(
"异常
: "
+
e
.
getMessage
()
);
}
finally
{
long
duration
=
System
.
currentTimeMillis
()
-
startTime
;
totalTime
.
addAndGet
(
duration
);
maxTime
.
updateAndGet
(
x
->
Math
.
max
(
x
,
duration
));
minTime
.
updateAndGet
(
x
->
Math
.
min
(
x
,
duration
));
latch
.
countDown
();
semaphore
.
release
();
// 释放许可
}
});
}
executorService
.
shutdown
();
// 关闭线程池
// 打印统计信息
try
{
latch
.
await
();
System
.
out
.
println
(
"完成所有请求"
);
long
averageTime
=
totalTime
.
get
()
/
TOTAL_REQUESTS
;
System
.
out
.
println
(
"平均耗时: "
+
averageTime
+
" ms"
);
System
.
out
.
println
(
"最大耗时: "
+
maxTime
.
get
()
+
" ms"
);
System
.
out
.
println
(
"最小耗时: "
+
(
minTime
.
get
()
==
Long
.
MAX_VALUE
?
0
:
minTime
.
get
())
+
" ms"
);
if
(!
executorService
.
awaitTermination
(
1
,
TimeUnit
.
MINUTES
))
{
executorService
.
shutdownNow
();
// 强制关闭
}
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
}
finally
{
executorService
.
shutdown
();
executorService
.
shutdownNow
();
}
long
averageTime
=
totalTime
.
get
()
/
TOTAL_REQUESTS
;
System
.
out
.
println
(
"完成所有请求"
);
System
.
out
.
println
(
"平均耗时: "
+
averageTime
+
" ms"
);
System
.
out
.
println
(
"最大耗时: "
+
maxTime
.
get
()
+
" ms"
);
System
.
out
.
println
(
"最小耗时: "
+
(
minTime
.
get
()
==
Long
.
MAX_VALUE
?
0
:
minTime
.
get
())
+
" ms"
);
}
}
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