io.github.linmoure.thread.config.ThreadPoolConfig Maven / Gradle / Ivy
package io.github.linmoure.thread.config;
import lombok.Data;
import java.io.Serializable;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@Data
public final class ThreadPoolConfig implements Serializable {
public static final int REJECTED_POLICY_0 = 0;
public static final int REJECTED_POLICY_1 = 1;
public static final int REJECTED_POLICY_2 = 2;
private String name;
private int corePoolSize;
private int maxPoolSize;
private int queueCapacity;
private int keepAliveSeconds;
private int rejectedPolicy = 0;
public BlockingQueue buildQueue() {
BlockingQueue blockingQueue;
if (this.queueCapacity <= 0) {
blockingQueue = new LinkedBlockingQueue<>();
} else {
blockingQueue = new ArrayBlockingQueue<>(this.queueCapacity);
}
return blockingQueue;
}
}