feat: 添加多线程配置
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.schisandra.share.application.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname GlobalConfig
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.common
|
||||||
|
* @Author: schisandra
|
||||||
|
* @CreateTime: 2024-02-16 15:57
|
||||||
|
* @Description: MVC全局处理
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class GlobalConfig extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
super.configureMessageConverters(converters);
|
||||||
|
converters.add(mappingJackson2HttpMessageConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
package com.schisandra.share.application.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.share.application.factory.CustomNameThreadFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程池的config管理
|
||||||
|
*
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/2/18
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ThreadPoolConfig {
|
||||||
|
|
||||||
|
@Bean(name = "rotateCaptchaThreadPool")
|
||||||
|
public ThreadPoolExecutor getLabelThreadPool() {
|
||||||
|
return new ThreadPoolExecutor(20, 100, 5,
|
||||||
|
TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
|
||||||
|
new CustomNameThreadFactory("rotateCaptcha"),
|
||||||
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package com.schisandra.share.application.factory;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义名称的线程工厂
|
||||||
|
*
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/2/18
|
||||||
|
*/
|
||||||
|
public class CustomNameThreadFactory implements ThreadFactory {
|
||||||
|
|
||||||
|
private static final AtomicInteger poolNumber = new AtomicInteger(1);
|
||||||
|
private final ThreadGroup group;
|
||||||
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||||
|
private final String namePrefix;
|
||||||
|
|
||||||
|
public CustomNameThreadFactory(String name) {
|
||||||
|
SecurityManager s = System.getSecurityManager();
|
||||||
|
group = (s != null) ? s.getThreadGroup() :
|
||||||
|
Thread.currentThread().getThreadGroup();
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
name = "pool";
|
||||||
|
}
|
||||||
|
namePrefix = name + "-" +
|
||||||
|
poolNumber.getAndIncrement() +
|
||||||
|
"-thread-";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
Thread t = new Thread(group, r,
|
||||||
|
namePrefix + threadNumber.getAndIncrement(),
|
||||||
|
0);
|
||||||
|
// 设置线程为非守护线程
|
||||||
|
if (t.isDaemon()){
|
||||||
|
t.setDaemon(false);
|
||||||
|
}
|
||||||
|
// 设置线程优先级为正常优先级
|
||||||
|
if (t.getPriority() != Thread.NORM_PRIORITY){
|
||||||
|
t.setPriority(Thread.NORM_PRIORITY);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,20 +1,20 @@
|
|||||||
package com.schisandra.share.domain.service.impl;
|
package com.schisandra.share.domain.service.impl;
|
||||||
|
|
||||||
import com.schisandra.share.common.enums.IsDeletedFlagEnum;
|
import com.schisandra.share.common.enums.IsDeletedFlagEnum;
|
||||||
import com.schisandra.share.domain.convert.SchisandraShareCircleBOConverter;
|
|
||||||
import com.schisandra.share.domain.bo.SchisandraShareCircleBO;
|
import com.schisandra.share.domain.bo.SchisandraShareCircleBO;
|
||||||
|
import com.schisandra.share.domain.convert.SchisandraShareCircleBOConverter;
|
||||||
import com.schisandra.share.domain.service.SchisandraShareCircleDomainService;
|
import com.schisandra.share.domain.service.SchisandraShareCircleDomainService;
|
||||||
import com.schisandra.share.infra.basic.entity.SchisandraShareCircle;
|
import com.schisandra.share.infra.basic.entity.SchisandraShareCircle;
|
||||||
import com.schisandra.share.infra.basic.service.SchisandraShareCircleService;
|
import com.schisandra.share.infra.basic.service.SchisandraShareCircleService;
|
||||||
import com.schisandra.share.infra.entity.AuthUserInfoEntity;
|
import com.schisandra.share.infra.entity.AuthUserInfoEntity;
|
||||||
import com.schisandra.share.infra.rpc.UserRpc;
|
import com.schisandra.share.infra.rpc.UserRpc;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分享圈 领域service实现了
|
* 分享圈 领域service实现了
|
||||||
@@ -63,8 +63,12 @@ public class SchisandraShareCircleDomainServiceImpl implements SchisandraShareCi
|
|||||||
List<SchisandraShareCircleBO> schisandraShareCircleBO_list = SchisandraShareCircleBOConverter.INSTANCE.convertEntityToBOList(schisandraShareCircleService.queryAll());
|
List<SchisandraShareCircleBO> schisandraShareCircleBO_list = SchisandraShareCircleBOConverter.INSTANCE.convertEntityToBOList(schisandraShareCircleService.queryAll());
|
||||||
ArrayList<SchisandraShareCircleBO> arrayList = new ArrayList<>();
|
ArrayList<SchisandraShareCircleBO> arrayList = new ArrayList<>();
|
||||||
for (SchisandraShareCircleBO schisandraShareCircleBO : schisandraShareCircleBO_list) {
|
for (SchisandraShareCircleBO schisandraShareCircleBO : schisandraShareCircleBO_list) {
|
||||||
|
CompletableFuture<AuthUserInfoEntity> futurePrice = CompletableFuture.supplyAsync(() -> {
|
||||||
|
AuthUserInfoEntity info = userRpc.getUserInfo(schisandraShareCircleBO.getUserId());
|
||||||
|
return info;
|
||||||
|
});
|
||||||
|
AuthUserInfoEntity userInfo = futurePrice.join();
|
||||||
SchisandraShareCircleBO shareCircleBO = new SchisandraShareCircleBO();
|
SchisandraShareCircleBO shareCircleBO = new SchisandraShareCircleBO();
|
||||||
AuthUserInfoEntity info = userRpc.getUserInfo(schisandraShareCircleBO.getUserId());
|
|
||||||
shareCircleBO.setUserId(schisandraShareCircleBO.getUserId());
|
shareCircleBO.setUserId(schisandraShareCircleBO.getUserId());
|
||||||
shareCircleBO.setParentId(schisandraShareCircleBO.getParentId());
|
shareCircleBO.setParentId(schisandraShareCircleBO.getParentId());
|
||||||
shareCircleBO.setId(schisandraShareCircleBO.getId());
|
shareCircleBO.setId(schisandraShareCircleBO.getId());
|
||||||
@@ -73,8 +77,8 @@ public class SchisandraShareCircleDomainServiceImpl implements SchisandraShareCi
|
|||||||
shareCircleBO.setViews(schisandraShareCircleBO.getViews());
|
shareCircleBO.setViews(schisandraShareCircleBO.getViews());
|
||||||
shareCircleBO.setCount(schisandraShareCircleBO.getCount());
|
shareCircleBO.setCount(schisandraShareCircleBO.getCount());
|
||||||
shareCircleBO.setName(schisandraShareCircleBO.getName());
|
shareCircleBO.setName(schisandraShareCircleBO.getName());
|
||||||
shareCircleBO.setAvatar(info.getAvatar());
|
shareCircleBO.setAvatar(userInfo.getAvatar());
|
||||||
shareCircleBO.setNickName(info.getNickName());
|
shareCircleBO.setNickName(userInfo.getNickName());
|
||||||
arrayList.add(shareCircleBO);
|
arrayList.add(shareCircleBO);
|
||||||
}
|
}
|
||||||
return arrayList;
|
return arrayList;
|
||||||
@@ -83,18 +87,18 @@ public class SchisandraShareCircleDomainServiceImpl implements SchisandraShareCi
|
|||||||
@Override
|
@Override
|
||||||
public Boolean updateCircleViews(String Id, Boolean isView) {
|
public Boolean updateCircleViews(String Id, Boolean isView) {
|
||||||
if (isView) {
|
if (isView) {
|
||||||
return schisandraShareCircleService.addView(Id)>0;
|
return schisandraShareCircleService.addView(Id) > 0;
|
||||||
}else {
|
} else {
|
||||||
return schisandraShareCircleService.delView(Id)>0;
|
return schisandraShareCircleService.delView(Id) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateCircleCounts(String Id, Boolean isCount) {
|
public Boolean updateCircleCounts(String Id, Boolean isCount) {
|
||||||
if (isCount) {
|
if (isCount) {
|
||||||
return schisandraShareCircleService.addCount(Id)>0;
|
return schisandraShareCircleService.addCount(Id) > 0;
|
||||||
}else {
|
} else {
|
||||||
return schisandraShareCircleService.delCount(Id)>0;
|
return schisandraShareCircleService.delCount(Id) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
<resultMap id="BaseResultMap" type="com.schisandra.share.infra.basic.entity.SchisandraShareUrl">
|
<resultMap id="BaseResultMap" type="com.schisandra.share.infra.basic.entity.SchisandraShareUrl">
|
||||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||||
|
<result column="type_name" jdbcType="VARCHAR" property="typeName"/>
|
||||||
<result column="type" jdbcType="VARCHAR" property="type"/>
|
<result column="type" jdbcType="VARCHAR" property="type"/>
|
||||||
<result column="password" jdbcType="VARCHAR" property="password"/>
|
<result column="password" jdbcType="VARCHAR" property="password"/>
|
||||||
<result column="description" jdbcType="VARCHAR" property="description"/>
|
<result column="description" jdbcType="VARCHAR" property="description"/>
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
package com.schisandra.system.application.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Classname GlobalConfig
|
||||||
|
* @BelongsProject: schisandra-cloud-storage
|
||||||
|
* @BelongsPackage: com.schisandra.auth.application.common
|
||||||
|
* @Author: schisandra
|
||||||
|
* @CreateTime: 2024-02-16 15:57
|
||||||
|
* @Description: MVC全局处理
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class GlobalConfig extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
super.configureMessageConverters(converters);
|
||||||
|
converters.add(mappingJackson2HttpMessageConverter());
|
||||||
|
}
|
||||||
|
|
||||||
|
private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
package com.schisandra.system.application.config;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.schisandra.system.application.factory.CustomNameThreadFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程池的config管理
|
||||||
|
*
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/2/18
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class ThreadPoolConfig {
|
||||||
|
|
||||||
|
@Bean(name = "rotateCaptchaThreadPool")
|
||||||
|
public ThreadPoolExecutor getLabelThreadPool() {
|
||||||
|
return new ThreadPoolExecutor(20, 100, 5,
|
||||||
|
TimeUnit.SECONDS, new LinkedBlockingDeque<>(40),
|
||||||
|
new CustomNameThreadFactory("rotateCaptcha"),
|
||||||
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package com.schisandra.system.application.factory;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义名称的线程工厂
|
||||||
|
*
|
||||||
|
* @author: landaiqing
|
||||||
|
* @date: 2024/2/18
|
||||||
|
*/
|
||||||
|
public class CustomNameThreadFactory implements ThreadFactory {
|
||||||
|
|
||||||
|
private static final AtomicInteger poolNumber = new AtomicInteger(1);
|
||||||
|
private final ThreadGroup group;
|
||||||
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||||
|
private final String namePrefix;
|
||||||
|
|
||||||
|
public CustomNameThreadFactory(String name) {
|
||||||
|
SecurityManager s = System.getSecurityManager();
|
||||||
|
group = (s != null) ? s.getThreadGroup() :
|
||||||
|
Thread.currentThread().getThreadGroup();
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
name = "pool";
|
||||||
|
}
|
||||||
|
namePrefix = name + "-" +
|
||||||
|
poolNumber.getAndIncrement() +
|
||||||
|
"-thread-";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
Thread t = new Thread(group, r,
|
||||||
|
namePrefix + threadNumber.getAndIncrement(),
|
||||||
|
0);
|
||||||
|
// 设置线程为非守护线程
|
||||||
|
if (t.isDaemon()){
|
||||||
|
t.setDaemon(false);
|
||||||
|
}
|
||||||
|
// 设置线程优先级为正常优先级
|
||||||
|
if (t.getPriority() != Thread.NORM_PRIORITY){
|
||||||
|
t.setPriority(Thread.NORM_PRIORITY);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user