Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
c28573c8
Commit
c28573c8
authored
Jul 20, 2018
by
Junling Bu
Browse files
chore[litemall-core]: 采用默认异步调度器。添加测试类。
parent
a64988a8
Changes
6
Hide whitespace changes
Inline
Side-by-side
litemall-core/src/main/java/org/linlinjava/litemall/core/config/AsyncConfig.java
0 → 100644
View file @
c28573c8
package
org.linlinjava.litemall.core.config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableAsync
;
@Configuration
@EnableAsync
public
class
AsyncConfig
{
}
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/ExecutorConfig.java
deleted
100644 → 0
View file @
a64988a8
package
org.linlinjava.litemall.core.notify
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* 异步线程池,用于异步发送通知
*/
@Configuration
@EnableScheduling
@EnableAsync
class
ExecutorConfig
{
@Value
(
"${NotifyPoolConfig.corePoolSize}"
)
private
int
corePoolSize
;
@Value
(
"${NotifyPoolConfig.maxPoolSize}"
)
private
int
maxPoolSize
;
@Value
(
"${NotifyPoolConfig.queueCapacity}"
)
private
int
queueCapacity
;
@Bean
(
name
=
"notifyAsync"
)
public
Executor
notifyAsync
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
executor
.
setCorePoolSize
(
corePoolSize
);
executor
.
setMaxPoolSize
(
maxPoolSize
);
executor
.
setQueueCapacity
(
queueCapacity
);
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
executor
.
setThreadNamePrefix
(
"NotifyExecutor-"
);
executor
.
initialize
();
return
executor
;
}
}
\ No newline at end of file
litemall-core/src/main/java/org/linlinjava/litemall/core/notify/LitemallNotifyService.java
View file @
c28573c8
...
...
@@ -17,7 +17,7 @@ public class LitemallNotifyService {
@Autowired
private
WXTemplateSendService
wxTemplateSendService
;
@Async
(
"notifyAsync"
)
@Async
public
void
notifySMSMessage
(
String
phoneNumber
,
String
message
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
...
...
@@ -33,7 +33,7 @@ public class LitemallNotifyService {
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
(
"notifyAsync"
)
@Async
public
void
notifyWXTemplate
(
String
token
,
String
touser
,
String
formId
,
ConfigUtil
.
NotifyType
notifyType
,
String
[]
params
)
{
if
(!
wxTemplateSendService
.
config
.
isEnable
())
return
;
...
...
@@ -51,7 +51,7 @@ public class LitemallNotifyService {
* @param notifyType 通知类别,通过该枚举值在配置文件中获取相应的模版ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
(
"notifyAsync"
)
@Async
public
void
notifySMSTemplate
(
String
phoneNumber
,
ConfigUtil
.
NotifyType
notifyType
,
String
[]
params
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
...
...
@@ -69,7 +69,7 @@ public class LitemallNotifyService {
* @param templateId 模板ID
* @param params 通知模版内容里的参数,类似"您的验证码为{1}"中{1}的值
*/
@Async
(
"notifyAsync"
)
@Async
public
void
notifySMSTemplate
(
String
phoneNumber
,
int
templateId
,
String
[]
params
)
{
if
(!
smsSendService
.
config
.
isEnable
())
return
;
...
...
@@ -83,7 +83,7 @@ public class LitemallNotifyService {
* @param setSubject 邮件标题
* @param setText 邮件内容
*/
@Async
(
"notifyAsync"
)
@Async
public
void
notifyMailMessage
(
String
setSubject
,
String
setText
)
{
if
(!
mailSendService
.
config
.
isEnable
())
return
;
...
...
litemall-core/src/main/resources/application.yaml
View file @
c28573c8
...
...
@@ -34,12 +34,6 @@ WXNotifyConfig:
-
name
:
captcha
templateId
:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 发送线程池配置
NotifyPoolConfig
:
corePoolSize
:
5
maxPoolSize
:
100
queueCapacity
:
50
#快鸟物流查询配置
express
:
appId
:
"
XXXXXXXXX"
...
...
litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java
0 → 100644
View file @
c28573c8
package
org.linlinjava.litemall.core
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
@Service
public
class
AsyncTask
{
@Async
public
void
asyncMethod
()
{
System
.
out
.
println
(
"Execute method asynchronously. "
+
Thread
.
currentThread
().
getName
());
}
public
void
nonasyncMethod
()
{
System
.
out
.
println
(
"Execute method nonasynchronously. "
+
Thread
.
currentThread
().
getName
());
}
}
litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTest.java
0 → 100644
View file @
c28573c8
package
org.linlinjava.litemall.core
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
/**
* 异步测试
*
*/
@WebAppConfiguration
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
AsyncTest
{
@Autowired
AsyncTask
task
;
@Test
public
void
test
()
{
task
.
asyncMethod
();
task
.
nonasyncMethod
();
}
}
Write
Preview
Supports
Markdown
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