|
|
@ -41,7 +41,7 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
|
|
|
|
|
|
|
|
private int corePoolSize = calculateCoreNum();
|
|
|
|
private int corePoolSize = calculateCoreNum();
|
|
|
|
|
|
|
|
|
|
|
|
private int maxPoolSize = corePoolSize + (corePoolSize >> 1);
|
|
|
|
private int maximumPoolSize = corePoolSize + (corePoolSize >> 1);
|
|
|
|
|
|
|
|
|
|
|
|
private long keepAliveTime = 30000L;
|
|
|
|
private long keepAliveTime = 30000L;
|
|
|
|
|
|
|
|
|
|
|
@ -150,16 +150,24 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @deprecated Use {@link #maximumPoolSize}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
|
|
|
public ThreadPoolBuilder maxPoolNum(int maximumPoolSize) {
|
|
|
|
|
|
|
|
return this.maximumPoolSize(maximumPoolSize);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Max pool num.
|
|
|
|
* Max pool num.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param maxPoolSize max pool num
|
|
|
|
* @param maximumPoolSize max pool num
|
|
|
|
* @return thread-pool builder
|
|
|
|
* @return thread-pool builder
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public ThreadPoolBuilder maxPoolNum(int maxPoolSize) {
|
|
|
|
public ThreadPoolBuilder maximumPoolSize(int maximumPoolSize) {
|
|
|
|
this.maxPoolSize = maxPoolSize;
|
|
|
|
this.maximumPoolSize = maximumPoolSize;
|
|
|
|
if (maxPoolSize < this.corePoolSize) {
|
|
|
|
if (maximumPoolSize < this.corePoolSize) {
|
|
|
|
this.corePoolSize = maxPoolSize;
|
|
|
|
this.corePoolSize = maximumPoolSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,7 +180,7 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
public ThreadPoolBuilder singlePool() {
|
|
|
|
public ThreadPoolBuilder singlePool() {
|
|
|
|
int singleNum = 1;
|
|
|
|
int singleNum = 1;
|
|
|
|
this.corePoolSize = singleNum;
|
|
|
|
this.corePoolSize = singleNum;
|
|
|
|
this.maxPoolSize = singleNum;
|
|
|
|
this.maximumPoolSize = singleNum;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -185,7 +193,7 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
public ThreadPoolBuilder singlePool(String threadNamePrefix) {
|
|
|
|
public ThreadPoolBuilder singlePool(String threadNamePrefix) {
|
|
|
|
int singleNum = 1;
|
|
|
|
int singleNum = 1;
|
|
|
|
this.corePoolSize = singleNum;
|
|
|
|
this.corePoolSize = singleNum;
|
|
|
|
this.maxPoolSize = singleNum;
|
|
|
|
this.maximumPoolSize = singleNum;
|
|
|
|
this.threadNamePrefix = threadNamePrefix;
|
|
|
|
this.threadNamePrefix = threadNamePrefix;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,12 +202,12 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
* Pool thread size.
|
|
|
|
* Pool thread size.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param corePoolSize core pool size
|
|
|
|
* @param corePoolSize core pool size
|
|
|
|
* @param maxPoolSize max pool size
|
|
|
|
* @param maximumPoolSize max pool size
|
|
|
|
* @return thread-pool builder
|
|
|
|
* @return thread-pool builder
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public ThreadPoolBuilder poolThreadSize(int corePoolSize, int maxPoolSize) {
|
|
|
|
public ThreadPoolBuilder poolThreadSize(int corePoolSize, int maximumPoolSize) {
|
|
|
|
this.corePoolSize = corePoolSize;
|
|
|
|
this.corePoolSize = corePoolSize;
|
|
|
|
this.maxPoolSize = maxPoolSize;
|
|
|
|
this.maximumPoolSize = maximumPoolSize;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -438,7 +446,7 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
|
|
|
|
initParam = new AbstractBuildThreadPoolTemplate.ThreadPoolInitParam(builder.threadFactory);
|
|
|
|
initParam = new AbstractBuildThreadPoolTemplate.ThreadPoolInitParam(builder.threadFactory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initParam.setCorePoolNum(builder.corePoolSize)
|
|
|
|
initParam.setCorePoolNum(builder.corePoolSize)
|
|
|
|
.setMaxPoolNum(builder.maxPoolSize)
|
|
|
|
.setMaximumPoolSize(builder.maximumPoolSize)
|
|
|
|
.setKeepAliveTime(builder.keepAliveTime)
|
|
|
|
.setKeepAliveTime(builder.keepAliveTime)
|
|
|
|
.setCapacity(builder.capacity)
|
|
|
|
.setCapacity(builder.capacity)
|
|
|
|
.setExecuteTimeOut(builder.executeTimeOut)
|
|
|
|
.setExecuteTimeOut(builder.executeTimeOut)
|
|
|
|