From c7563259c1ada319394af46108ec49d3c657f8a4 Mon Sep 17 00:00:00 2001 From: zxq171 Date: Mon, 6 Jan 2020 11:14:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=BC=82=E6=AD=A5=E9=A2=84=E7=83=AD?= =?UTF-8?q?Redis=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 From 750371ef566581ce631ac50cbc7f2798dea6db54 Mon Sep 17 00:00:00 2001 From: zxq171 Date: Tue, 7 Jan 2020 11:07:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=B9=E5=99=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=BC=82=E6=AD=A5=E9=A2=84=E7=83=AD?= =?UTF-8?q?Redis=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sso/config/RedisCacheThreadPool.java | 10 +++++++--- .../sso/redis/IRedisCacheStartupService.java | 18 ++++++++++++++++++ .../sso/redis/RedisCacheStartupService.java | 14 +++++++++++--- .../impl/SyChanmgfunVistUrlService.java | 7 +++---- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java 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 index f2da5f7..fb316a1 100644 --- 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 @@ -4,7 +4,7 @@ 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; +import tech.mhuang.interchan.sso.redis.IRedisCacheStartupService; /** * @ClassName: RedisCacheThreadPool @@ -15,7 +15,8 @@ import tech.mhuang.interchan.sso.redis.RedisCacheStartupService; */ @Configuration public class RedisCacheThreadPool extends SpringThreadPool { - private final String DEFAULT_NAME = "redisCacheThreadPool"; + private static final String DEFAULT_NAME = "redisCacheThreadPool"; + public RedisCacheThreadPool() { super(); @@ -23,9 +24,12 @@ public class RedisCacheThreadPool extends SpringThreadPool { } @Bean("rediscacheThreadPool") - public RedisCacheThreadPool redisCacheThreadPoolFramework(RedisCacheStartupService redisCacheStartupService, SpringContextHolder springContextHolder) { + public RedisCacheThreadPool redisCacheThreadPoolFramework(IRedisCacheStartupService redisCacheStartupService, SpringContextHolder springContextHolder) { this.initialize(); this.execute(redisCacheStartupService); return this; } + + + } diff --git a/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java new file mode 100644 index 0000000..c128224 --- /dev/null +++ b/inter-boot-sso/src/main/java/tech/mhuang/interchan/sso/redis/IRedisCacheStartupService.java @@ -0,0 +1,18 @@ +package tech.mhuang.interchan.sso.redis; + +/** + * @ClassName: IRedisCacheStartupService + * @Author: Ever + * @Description: 缓存redis + * @Date: 2020/1/6 11:53 + * @Version: 1.0 + */ +public interface IRedisCacheStartupService extends Runnable { + /** + * 缓存redis + * + * @return + */ + String redisCache(); + +} 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 23fcf52..74e33a8 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 @@ -8,6 +8,7 @@ import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunExcludeUrl; import tech.mhuang.interchan.sso.sysfunvisturl.mapper.SyChanmgfunVistUrlmMapper; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -20,17 +21,18 @@ import java.util.stream.Collectors; * @Version: 1.0 */ @Service -public class RedisCacheStartupService implements Runnable { +public class RedisCacheStartupService implements IRedisCacheStartupService { @Autowired private SyChanmgfunVistUrlmMapper syChanmgfunVistUrlmMapper; @Autowired private SysFunvisturlRedisOperator syChanmgfunRedisOperator; - + Map map = new HashMap(); + private static final String SUCCESS = "success"; @Override - public void run() { + public String redisCache() { //查询数据库,并放入缓存中 List urls = syChanmgfunVistUrlmMapper.getExcludeUrl(); if (CollectionUtil.isNotEmpty(urls)) { @@ -38,5 +40,11 @@ public class RedisCacheStartupService implements Runnable { urls.parallelStream().collect(Collectors.groupingBy(SyChanmgfunExcludeUrl::getType)); syChanmgfunRedisOperator.cacheData(AuthConstant.AUTH_DICT_KEY, datas); } + return SUCCESS; + } + + @Override + public void run() { + redisCache(); } } 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 8f4fa2b..d357d15 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 @@ -14,7 +14,7 @@ import tech.mhuang.ext.interchan.protocol.InsertInto; import tech.mhuang.ext.spring.util.DataUtil; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmAddDTO; import tech.mhuang.interchan.protocol.sso.sysfunvisturl.SyChanmgfunVistUrlmQryDTO; -import tech.mhuang.interchan.sso.redis.RedisCacheStartupService; +import tech.mhuang.interchan.sso.redis.IRedisCacheStartupService; import tech.mhuang.interchan.sso.sysfunvisturl.cache.SysFunvisturlRedisOperator; import tech.mhuang.interchan.sso.sysfunvisturl.entity.SyChanmgfunVistUrlm; import tech.mhuang.interchan.sso.sysfunvisturl.mapper.SyChanmgfunVistUrlmMapper; @@ -22,7 +22,6 @@ import tech.mhuang.interchan.sso.sysfunvisturl.service.ISyChanmgfunVistUrlServic import tech.mhuang.interchan.sso.sysrole.entity.SysRole; import tech.mhuang.interchan.sso.sysuser.entity.SysUser; - import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -50,7 +49,7 @@ public class SyChanmgfunVistUrlService private SysFunvisturlRedisOperator syChanmgfunRedisOperator; @Autowired - private RedisCacheStartupService redisCacheStartupService; + private IRedisCacheStartupService redisCacheStartupService; /** * @param funid @@ -221,7 +220,7 @@ public class SyChanmgfunVistUrlService if (StringUtil.isNotBlank(userId)) { this.setVistUrlPowerNow(userId); } else { - redisCacheStartupService.run(); + redisCacheStartupService.redisCache(); } } -- Gitee