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 237a40efe46ac86a5422aa99076bb734435b8354..13ebe9c658323997cf730d1d4f5d0020fd02f876 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 0000000000000000000000000000000000000000..f2da5f74aeca8399c8f61dc0ad062e38b60581b1 --- /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 bc48d558b74595a4aa96cc2a64d67eba9836dfb8..f2fbcdcde958c9184142f2d03807a60af04c7b95 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 336185bd64353c9db7417eedf6307e1350d9fbec..23fcf527185fc79a6f6e1f926adcc859c10d58cb 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 613b94379c14888c7da4f2b647d3293f326d1969..8f4fa2b6281ead7749de6a2996552ce5fc6da601 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(); } }