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
75872a14
Commit
75872a14
authored
Oct 29, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
释放内存
parent
dde171dc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
5 deletions
+75
-5
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+6
-3
MaterialApiServiceImpl.java
...nage/service/service/out/impl/MaterialApiServiceImpl.java
+8
-2
QWmediaTest.java
haoban-manage3-service/src/test/java/QWmediaTest.java
+61
-0
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
75872a14
...
@@ -29,14 +29,14 @@ public class ImageCombined {
...
@@ -29,14 +29,14 @@ public class ImageCombined {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ImageCombined
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ImageCombined
.
class
);
private
static
final
Cache
<
String
,
BufferedImage
>
imageCache
=
Caffeine
.
newBuilder
()
private
static
final
Cache
<
String
,
BufferedImage
>
imageCache
=
Caffeine
.
newBuilder
()
.
maximumWeight
(
100
*
1024
*
1024
)
// 10
0MB
.
maximumWeight
(
50
*
1024
*
1024
)
// 5
0MB
.
weigher
((
String
key
,
BufferedImage
image
)
->
image
.
getWidth
()
*
image
.
getHeight
()
/
4
)
.
weigher
((
String
key
,
BufferedImage
image
)
->
image
.
getWidth
()
*
image
.
getHeight
()
/
4
)
.
expireAfterAccess
(
30
,
TimeUnit
.
MINUTES
)
// 可设置失效时间
.
expireAfterAccess
(
30
,
TimeUnit
.
MINUTES
)
// 可设置失效时间
.
build
();
.
build
();
public
static
final
ThreadPoolExecutor
EXECUTOR
=
new
ThreadPoolExecutor
(
public
static
final
ThreadPoolExecutor
EXECUTOR
=
new
ThreadPoolExecutor
(
2
0
,
1
0
,
5
0
,
3
0
,
60L
,
60L
,
TimeUnit
.
SECONDS
,
TimeUnit
.
SECONDS
,
new
ArrayBlockingQueue
<>(
100
),
new
ArrayBlockingQueue
<>(
100
),
...
@@ -95,6 +95,9 @@ public class ImageCombined {
...
@@ -95,6 +95,9 @@ public class ImageCombined {
ImageIO
.
write
(
combinedImage
,
"jpg"
,
baos
);
ImageIO
.
write
(
combinedImage
,
"jpg"
,
baos
);
// 返回字节数组
// 返回字节数组
return
baos
.
toByteArray
();
return
baos
.
toByteArray
();
}
finally
{
qrCodeImage
.
flush
();
combinedImage
.
flush
();
}
}
}
}
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/MaterialApiServiceImpl.java
View file @
75872a14
...
@@ -6,11 +6,13 @@ import java.util.Collections;
...
@@ -6,11 +6,13 @@ import java.util.Collections;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
com.gic.commons.util.TraceIdUtil
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.service.context.combined.ImageCombined
;
import
com.gic.haoban.manage.service.context.combined.ImageCombined
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.redis.data.util.RedisUtil
;
...
@@ -534,8 +536,12 @@ public class MaterialApiServiceImpl implements MaterialApiService {
...
@@ -534,8 +536,12 @@ public class MaterialApiServiceImpl implements MaterialApiService {
Future
<
JSONResponse
>
future
=
null
;
Future
<
JSONResponse
>
future
=
null
;
JSONResponse
json
=
null
;
JSONResponse
json
=
null
;
try
{
try
{
future
=
ImageCombined
.
EXECUTOR
.
submit
(()
->
future
=
ImageCombined
.
EXECUTOR
.
submit
(()
->
{
materialService
.
getMaterialIdByCombined
(
wxEnterpriseId
,
combinedQDTO
));
TraceIdUtil
.
traceBegin
(
TraceIdUtil
.
EntranceType
.
QUARTZ
);
JSONResponse
jr
=
materialService
.
getMaterialIdByCombined
(
wxEnterpriseId
,
combinedQDTO
);
TraceIdUtil
.
traceEnd
();
return
jr
;
});
json
=
future
.
get
();
json
=
future
.
get
();
if
(
json
.
getErrorCode
()
==
0
)
{
if
(
json
.
getErrorCode
()
==
0
)
{
String
mediaId
=
json
.
getResult
().
toString
()
;
String
mediaId
=
json
.
getResult
().
toString
()
;
...
...
haoban-manage3-service/src/test/java/QWmediaTest.java
View file @
75872a14
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.gic.api.base.commons.JSONResponse
;
import
com.gic.api.base.commons.JSONResponse
;
import
com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO
;
import
com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
...
@@ -15,6 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -15,6 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
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.atomic.AtomicLong
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
locations
=
{
"classpath:applicationContext-conf.xml"
})
@ContextConfiguration
(
locations
=
{
"classpath:applicationContext-conf.xml"
})
public
class
QWmediaTest
{
public
class
QWmediaTest
{
...
@@ -45,4 +54,56 @@ public class QWmediaTest {
...
@@ -45,4 +54,56 @@ public class QWmediaTest {
}
}
public
static
void
main
(
String
[]
args
)
{
int
TOTAL_REQUESTS
=
100
;
// 总请求数
List
<
String
>
list
=
FileUtil
.
readLines
(
"/Users/wang/Downloads/image.txt"
,
"UTF-8"
);
JSONObject
jo
=
new
JSONObject
();
jo
.
put
(
"wxEnterpriseId"
,
"b18ffdc9d0644912865a248859914d80"
);
jo
.
put
(
"qrCodeUrl"
,
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-4ffc77073ca1476fb264bf1be9f11383.png"
);
jo
.
put
(
"showStyle"
,
"0"
);
jo
.
put
(
"lineOne"
,
"门店CCA"
);
jo
.
put
(
"lineTwo"
,
"宇智222为您推荐"
);
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
50
);
// 创建线程池
CountDownLatch
latch
=
new
CountDownLatch
(
TOTAL_REQUESTS
);
// 创建CountDownLatch,初始值为请求总数
// 用于统计请求耗时
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
++)
{
final
int
requestId
=
i
;
executorService
.
submit
(()
->
{
long
startTime
=
System
.
currentTimeMillis
();
try
{
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
(
"异常"
);
}
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
();
}
});
}
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"
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
}
finally
{
executorService
.
shutdown
();
}
}
}
}
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