mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
引入第三方平台任务线程池
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 开源代码,仅供学习和交流研究使用,商用请联系三丙
|
||||
* 微信:mohan_88888
|
||||
* 抖音:程序员三丙
|
||||
* 付费课程知识星球:https://t.zsxq.com/aKtXo
|
||||
*/
|
||||
package com.jsowell.framework.async;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
public class JsowellThreadFactory {
|
||||
public static final String THREAD_TOPIC_SEPARATOR = " | ";
|
||||
|
||||
public static ThreadFactory forName(String name) {
|
||||
return new ThreadFactoryBuilder()
|
||||
.setNameFormat(name)
|
||||
.setDaemon(true)
|
||||
.setPriority(Thread.NORM_PRIORITY)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ThreadFactory forName(String name, int priority) {
|
||||
return new ThreadFactoryBuilder()
|
||||
.setNameFormat(name)
|
||||
.setDaemon(true)
|
||||
.setPriority(priority)
|
||||
.build();
|
||||
}
|
||||
public static void updateCurrentThreadName(String threadSuffix) {
|
||||
String name = Thread.currentThread().getName();
|
||||
int spliteratorIndex = name.indexOf(THREAD_TOPIC_SEPARATOR);
|
||||
if (spliteratorIndex > 0) {
|
||||
name = name.substring(0, spliteratorIndex);
|
||||
}
|
||||
name = name + THREAD_TOPIC_SEPARATOR + threadSuffix;
|
||||
Thread.currentThread().setName(name);
|
||||
}
|
||||
|
||||
public static void addThreadNamePrefix(String prefix) {
|
||||
String name = Thread.currentThread().getName();
|
||||
name = prefix + "-" + name;
|
||||
Thread.currentThread().setName(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -49,6 +49,22 @@ public class ThreadPoolConfig {
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于处理互联互通任务的线程池
|
||||
*/
|
||||
@Bean(name = "thirdpartyTaskExecutor")
|
||||
public ThreadPoolTaskExecutor thirdpartyTaskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setMaxPoolSize(maxPoolSize/10);
|
||||
executor.setCorePoolSize(corePoolSize/10);
|
||||
executor.setQueueCapacity(queueCapacity/10);
|
||||
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||
// 线程池对拒绝任务(无线程可用)的处理策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
// log.info("threadPoolTaskExecutor创建成功");
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行周期性或定时任务
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user