mirror of https://github.com/longtai-cn/hippo4j
parent
2bb07c11c3
commit
0e713a370e
@ -0,0 +1,52 @@
|
|||||||
|
package io.dynamic.threadpool.common.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 队列类型枚举
|
||||||
|
*
|
||||||
|
* @author chen.ma
|
||||||
|
* @date 2021/6/25 12:30
|
||||||
|
*/
|
||||||
|
public enum QueueTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.ArrayBlockingQueue}
|
||||||
|
*/
|
||||||
|
ARRAY_BLOCKING_QUEUE(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.LinkedBlockingQueue}
|
||||||
|
*/
|
||||||
|
Linked_Blocking_QUEUE(2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.LinkedBlockingDeque}
|
||||||
|
*/
|
||||||
|
Linked_Blocking_Deque(3),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.SynchronousQueue}
|
||||||
|
*/
|
||||||
|
SynchronousQueue(4),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.LinkedTransferQueue}
|
||||||
|
*/
|
||||||
|
LINKED_TRANSFER_QUEUE(5),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link java.util.concurrent.PriorityBlockingQueue}
|
||||||
|
*/
|
||||||
|
PriorityBlockingQueue(6),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link "io.dynamic.threadpool.starter.core.ResizableCapacityLinkedBlockIngQueue"}
|
||||||
|
*/
|
||||||
|
Resizable_LINKED_Blocking_QUEUE(9);
|
||||||
|
|
||||||
|
public Integer type;
|
||||||
|
|
||||||
|
QueueTypeEnum(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package io.dynamic.threadpool.starter.toolkit;
|
||||||
|
|
||||||
|
import io.dynamic.threadpool.common.enums.QueueTypeEnum;
|
||||||
|
import io.dynamic.threadpool.starter.core.ResizableCapacityLinkedBlockIngQueue;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程池修改工具类
|
||||||
|
*
|
||||||
|
* @author chen.ma
|
||||||
|
* @date 2021/6/25 17:19
|
||||||
|
*/
|
||||||
|
public class ThreadPoolChangeUtil {
|
||||||
|
|
||||||
|
public static void changePool(ThreadPoolExecutor executor, Integer coreSize, Integer maxSize, Integer queueType, Integer capacity, Integer keepAliveTime) {
|
||||||
|
if (coreSize != null) {
|
||||||
|
executor.setCorePoolSize(coreSize);
|
||||||
|
}
|
||||||
|
if (maxSize != null) {
|
||||||
|
executor.setMaximumPoolSize(maxSize);
|
||||||
|
}
|
||||||
|
if (capacity != null && Objects.equals(QueueTypeEnum.Resizable_LINKED_Blocking_QUEUE.type, queueType)) {
|
||||||
|
ResizableCapacityLinkedBlockIngQueue queue = (ResizableCapacityLinkedBlockIngQueue) executor.getQueue();
|
||||||
|
queue.setCapacity(capacity);
|
||||||
|
}
|
||||||
|
if (keepAliveTime != null) {
|
||||||
|
executor.setKeepAliveTime(keepAliveTime, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package io.dynamic.threadpool.server.controller;
|
||||||
|
|
||||||
|
import io.dynamic.threadpool.common.constant.Constants;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务控制器
|
||||||
|
*
|
||||||
|
* @author chen.ma
|
||||||
|
* @date 2021/6/25 18:31
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Constants.BASE_PATH)
|
||||||
|
public class BizController {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue