parent
711e2a9d8e
commit
077ba1bb3e
@ -0,0 +1,32 @@
|
||||
package com.mashibing.common.utils;
|
||||
|
||||
import com.mashibing.common.pojo.StandardSubmit;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: CMPPSubmitRepoMapUtil
|
||||
* @Description: 临时存储StandardSubmit对象
|
||||
* @date 2025/6/15 17:07
|
||||
*/
|
||||
|
||||
public class CMPPSubmitRepoMapUtil {
|
||||
|
||||
private static final ConcurrentHashMap<String, StandardSubmit> TEMP_SUBMIT = new ConcurrentHashMap<>();
|
||||
|
||||
public static StandardSubmit put(int sequence, StandardSubmit standardSubmit) {
|
||||
return TEMP_SUBMIT.put(sequence + "", standardSubmit);
|
||||
}
|
||||
|
||||
public static StandardSubmit get(int sequence) {
|
||||
return TEMP_SUBMIT.get(sequence + "");
|
||||
}
|
||||
|
||||
public static StandardSubmit remove(int sequence) {
|
||||
return TEMP_SUBMIT.remove(sequence + "");
|
||||
}
|
||||
|
||||
private CMPPSubmitRepoMapUtil() {
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.mashibing.smsgateway.config;
|
||||
|
||||
import cn.hippo4j.core.executor.DynamicThreadPool;
|
||||
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: ThreadPoolConfig
|
||||
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||
* @date 2025/6/16 20:35
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
@Bean
|
||||
@DynamicThreadPool
|
||||
public ThreadPoolExecutor cmppSubmitPool() {
|
||||
// 短信提交应答
|
||||
String threadPoolId = "cmpp-submit";
|
||||
|
||||
return ThreadPoolBuilder.builder()
|
||||
// 指定线程名称的前缀
|
||||
.threadFactory(threadPoolId)
|
||||
// 线程池在Hippo4j中的唯一标识
|
||||
.threadPoolId(threadPoolId)
|
||||
// 代表动态线程池
|
||||
.dynamicPool()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DynamicThreadPool
|
||||
public ThreadPoolExecutor cmppDeliverPool() {
|
||||
//短信状态报告应答
|
||||
String threadPoolId = "cmpp-deliver";
|
||||
|
||||
return ThreadPoolBuilder.builder()
|
||||
.threadFactory(threadPoolId)
|
||||
.threadPoolId(threadPoolId)
|
||||
.dynamicPool()
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.mashibing.smsgateway.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author heqijun
|
||||
* @ClassName: TestController
|
||||
* @Description: 动态线程池测试类
|
||||
* @date 2025/6/17 16:57
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@Resource
|
||||
ThreadPoolExecutor cmppSubmitPool;
|
||||
|
||||
@Resource
|
||||
ThreadPoolExecutor cmppDeliverPool;
|
||||
|
||||
@GetMapping("test")
|
||||
public String test() {
|
||||
cmppSubmitPool.execute(() -> System.out.println("【" + LocalDateTime.now() + "】"
|
||||
+ Thread.currentThread().getName()));
|
||||
return "OK";
|
||||
}
|
||||
}
|
Loading…
Reference in new issue