-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Frodez/0.3-alpha
0.3 alpha
- Loading branch information
Showing
41 changed files
with
390 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package frodez.config.async; | ||
|
||
import frodez.util.spring.ContextUtil; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
/** | ||
* 异步配置 | ||
* @author Frodez | ||
* @date 2019-04-15 | ||
*/ | ||
@Slf4j | ||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig { | ||
|
||
@Bean | ||
public Executor getAsyncExecutor() { | ||
AsyncProperties properties = ContextUtil.get(AsyncProperties.class); | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
int availableProcessors = Runtime.getRuntime().availableProcessors(); | ||
int corePoolSize = Math.round(availableProcessors * properties.getCoreThreadTimes()); | ||
int maxPoolSize = Math.round(availableProcessors * properties.getMaxThreadTimes()); | ||
int queueCapacity = Math.round(maxPoolSize * properties.getQueueFactors()); | ||
executor.setCorePoolSize(corePoolSize); | ||
executor.setMaxPoolSize(maxPoolSize); | ||
executor.setQueueCapacity(queueCapacity); | ||
executor.setKeepAliveSeconds(properties.getKeepAliveSeconds()); | ||
executor.setThreadNamePrefix(properties.getThreadNamePrefix()); | ||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | ||
executor.initialize(); | ||
log.info("async executor is running now!"); | ||
log.info("async config:{}corePoolSize, {}maxPoolSize, {}queueCapacity, {}keepAliveSeconds, {}threadNamePrefix", | ||
corePoolSize, maxPoolSize, queueCapacity, properties.getKeepAliveSeconds(), properties | ||
.getThreadNamePrefix()); | ||
return executor; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package frodez.config.async; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* 异步任务配置 | ||
* @author Frodez | ||
* @date 2019-04-15 | ||
*/ | ||
@Data | ||
@Component | ||
@PropertySource(value = { "classpath:settings/${spring.profiles.active}/async.properties" }) | ||
@ConfigurationProperties(prefix = "async") | ||
public class AsyncProperties { | ||
|
||
/** | ||
* 核心线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。 | ||
*/ | ||
private float coreThreadTimes = 0.5F; | ||
|
||
/** | ||
* 最大线程基数,实际数量等于系统环境可用核心数乘以该基数并四舍五入。 | ||
*/ | ||
private float maxThreadTimes = 1.0F; | ||
|
||
/** | ||
* 队列规模因子,队列最大长度等于计算出的最大线程数乘以规模因子并四舍五入。 | ||
*/ | ||
private float queueFactors = 16.0F; | ||
|
||
/** | ||
* 线程最长活跃时间,单位为秒 | ||
*/ | ||
private int keepAliveSeconds = 60; | ||
|
||
/** | ||
* 线程名前缀 | ||
*/ | ||
private String threadNamePrefix = "async"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.