From c7563259c1ada319394af46108ec49d3c657f8a4 Mon Sep 17 00:00:00 2001 From: zxq171 Date: Mon, 6 Jan 2020 11:14:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=BC=82=E6=AD=A5=E9=A2=84=E7=83=ADRedis?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interchan/sso/config/AsyncTaskConfig.java | 4 +-- .../sso/config/RedisCacheThreadPool.java | 31 +++++++++++++++++++ .../sso/redis/RedisCacheStartup.java | 11 ++++--- .../sso/redis/RedisCacheStartupService.java | 26 ++-------------- .../impl/SyChanmgfunVistUrlService.java | 2 +- 5 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java index 237a40e..13ebe9c 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/AsyncTaskConfig.java @@ -2,7 +2,6 @@ package tech.mhuang.interchan.sso.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import tech.mhuang.core.async.AsyncTaskService; import tech.mhuang.core.async.DefaultAsyncTaskSupport; /** @@ -16,8 +15,9 @@ import tech.mhuang.core.async.DefaultAsyncTaskSupport; public class AsyncTaskConfig { @Bean - public AsyncTaskService buildAsync() { + public DefaultAsyncTaskSupport buildAsync() { return new DefaultAsyncTaskSupport(); } + } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java new file mode 100644 index 0000000..f2da5f7 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/config/RedisCacheThreadPool.java @@ -0,0 +1,31 @@ +package tech.mhuang.interchan.sso.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import tech.mhuang.ext.spring.pool.SpringThreadPool; +import tech.mhuang.ext.spring.start.SpringContextHolder; +import tech.mhuang.interchan.sso.redis.RedisCacheStartupService; + +/** + * @ClassName: RedisCacheThreadPool + * @Author: Ever + * @Description: redis缓存线程池 + * @Date: 2020/1/6 10:24 + * @Version: 1.0 + */ +@Configuration +public class RedisCacheThreadPool extends SpringThreadPool { + private final String DEFAULT_NAME = "redisCacheThreadPool"; + + public RedisCacheThreadPool() { + super(); + setBeanName(DEFAULT_NAME); + } + + @Bean("rediscacheThreadPool") + public RedisCacheThreadPool redisCacheThreadPoolFramework(RedisCacheStartupService redisCacheStartupService, SpringContextHolder springContextHolder) { + this.initialize(); + this.execute(redisCacheStartupService); + return this; + } +} diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java index bc48d55..f2fbcdc 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartup.java @@ -4,7 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.stereotype.Component; -import tech.mhuang.core.async.AsyncTaskService; +import tech.mhuang.core.async.DefaultAsyncTaskSupport; +import tech.mhuang.interchan.sso.config.RedisCacheThreadPool; /** * @ClassName: RedisCacheStartup @@ -18,11 +19,13 @@ import tech.mhuang.core.async.AsyncTaskService; public class RedisCacheStartup implements CommandLineRunner { @Autowired - private AsyncTaskService asyncTaskService; + private DefaultAsyncTaskSupport defaultAsyncTaskSupport; + @Autowired + private RedisCacheThreadPool redisCacheThreadPool; @Override - public void run(String... args) throws Exception { - asyncTaskService.submit(new RedisCacheStartupService()); + public void run(String... args) { + defaultAsyncTaskSupport.executor(redisCacheThreadPool); } } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java index 336185b..23fcf52 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/RedisCacheStartupService.java @@ -1,10 +1,7 @@ package tech.mhuang.interchan.sso.redis; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import tech.mhuang.core.async.AsyncTask; -import tech.mhuang.core.async.AsyncTaskService; import tech.mhuang.core.util.CollectionUtil; import tech.mhuang.ext.interchan.auth.constant.AuthConstant; import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; @@ -23,15 +20,8 @@ import java.util.stream.Collectors; * @Version: 1.0 */ @Service -@Slf4j -public class RedisCacheStartupService implements AsyncTask { - /** - * 成功 - */ - private static final String SUCCESS = "success"; +public class RedisCacheStartupService implements Runnable { - @Autowired - AsyncTaskService asyncTaskService; @Autowired private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; @@ -40,17 +30,7 @@ public class RedisCacheStartupService implements AsyncTask { @Override - public void onSuccess(Object result) { - log.info("redis异步加载:{}", result); - } - - @Override - public void onFailed(Throwable t) { - log.error("redis异步加载:{}", t.getMessage()); - } - - @Override - public String execute() { + public void run() { //查询数据库,并放入缓存中 List urls = syChanmgfunVistUrlmMapper.getExcludeUrl(); if (CollectionUtil.isNotEmpty(urls)) { @@ -58,7 +38,5 @@ public class RedisCacheStartupService implements AsyncTask { urls.parallelStream().collect(Collectors.groupingBy(SyChanmgfunExcludeUrl::getType)); syChanmgfunRedisOperator.cacheData(AuthConstant.AUTH_DICT_KEY, datas); } - return SUCCESS; } - } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java index 613b943..8f4fa2b 100644 --- a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/sysfunvisturl/service/impl/SyChanmgfunVistUrlService.java @@ -221,7 +221,7 @@ public class SyChanmgfunVistUrlService if (StringUtil.isNotBlank(userId)) { this.setVistUrlPowerNow(userId); } else { - redisCacheStartupService.execute(); + redisCacheStartupService.run(); } } -- Gitee