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
6f8d4f95
Commit
6f8d4f95
authored
Oct 29, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
动态调整线程池
parent
b3e11c5c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+29
-0
ApolloUtils.java
.../java/com/gic/haoban/manage/service/util/ApolloUtils.java
+22
-0
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
6f8d4f95
package
com
.
gic
.
haoban
.
manage
.
service
.
context
.
combined
;
package
com
.
gic
.
haoban
.
manage
.
service
.
context
.
combined
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.model.ConfigChange
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.api.qdto.combined.CombinedQDTO
;
import
com.gic.haoban.manage.service.util.ApolloUtils
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
net.coobird.thumbnailator.Thumbnails
;
import
net.coobird.thumbnailator.Thumbnails
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -27,6 +33,8 @@ import java.util.concurrent.TimeUnit;
...
@@ -27,6 +33,8 @@ import java.util.concurrent.TimeUnit;
*/
*/
public
class
ImageCombined
{
public
class
ImageCombined
{
private
static
final
String
APPLICATION
=
"application"
;
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
()
...
@@ -44,6 +52,27 @@ public class ImageCombined {
...
@@ -44,6 +52,27 @@ public class ImageCombined {
new
ThreadPoolExecutor
.
AbortPolicy
()
new
ThreadPoolExecutor
.
AbortPolicy
()
);
);
private
ImageCombined
()
{
Config
config
=
ConfigService
.
getAppConfig
();
config
.
addChangeListener
(
this
::
refreshThreadPool
);
}
private
void
refreshThreadPool
(
ConfigChangeEvent
changeEvent
)
{
if
(!
StringUtils
.
equals
(
changeEvent
.
getNamespace
(),
APPLICATION
))
{
return
;
}
ConfigChange
combinedCorePoolSizeChange
=
changeEvent
.
getChange
(
"combinedCorePoolSize"
);
ConfigChange
combinedMaximumPoolSizeChange
=
changeEvent
.
getChange
(
"combinedMaximumPoolSize"
);
if
((
combinedCorePoolSizeChange
!=
null
&&
combinedCorePoolSizeChange
.
getNewValue
()
!=
null
)
||
(
combinedMaximumPoolSizeChange
!=
null
&&
combinedMaximumPoolSizeChange
.
getNewValue
()
!=
null
))
{
Integer
corePoolSize
=
ApolloUtils
.
combinedCorePoolSize
();
Integer
maximumPoolSize
=
ApolloUtils
.
combinedMaximumPoolSize
();
logger
.
info
(
"动态调整线程池corePoolSize:{},maximumPoolSize:{}"
,
corePoolSize
,
maximumPoolSize
);
EXECUTOR
.
setCorePoolSize
(
corePoolSize
);
EXECUTOR
.
setMaximumPoolSize
(
maximumPoolSize
);
}
}
public
static
final
String
IMAGE_REDIS_KEY
=
"haoban-manage3-service:combined_image:"
;
public
static
final
String
IMAGE_REDIS_KEY
=
"haoban-manage3-service:combined_image:"
;
private
static
final
int
MAX_HEIGHT_NO_WHITE_SPACE
=
1500
;
private
static
final
int
MAX_HEIGHT_NO_WHITE_SPACE
=
1500
;
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/ApolloUtils.java
View file @
6f8d4f95
...
@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.util;
...
@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.util;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.ConfigService
;
import
java.util.Map
;
public
class
ApolloUtils
{
public
class
ApolloUtils
{
/**
/**
...
@@ -14,4 +16,24 @@ public class ApolloUtils {
...
@@ -14,4 +16,24 @@ public class ApolloUtils {
String
messageCenterSwitch
=
config
.
getProperty
(
"messageCenterSwitch"
,
"0"
);
String
messageCenterSwitch
=
config
.
getProperty
(
"messageCenterSwitch"
,
"0"
);
return
"1"
.
equals
(
messageCenterSwitch
);
return
"1"
.
equals
(
messageCenterSwitch
);
}
}
/**
* 线程池核心线程数
* @return
*/
public
static
Integer
combinedCorePoolSize
()
{
Config
config
=
ConfigService
.
getAppConfig
();
String
corePoolSize
=
config
.
getProperty
(
"combinedCorePoolSize"
,
"20"
);
return
Integer
.
parseInt
(
corePoolSize
);
}
/**
* 线程池最大线程数
* @return
*/
public
static
Integer
combinedMaximumPoolSize
()
{
Config
config
=
ConfigService
.
getAppConfig
();
String
maximumPoolSize
=
config
.
getProperty
(
"combinedMaximumPoolSize"
,
"40"
);
return
Integer
.
parseInt
(
maximumPoolSize
);
}
}
}
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