public class ResourcePoolConfig {
private ResourcePoolConfig (Builder builder) {
this.name = builder.name;
this.maxTotal = builder.maxTotal;
this.maxIdle = builder.maxIdle;
this.minIdle = builder.minIdle;
public String getName() {
public int getMaxTotal() {
public int getMaxIdle() {
public int getMinIdle() {
public String toString() {
return "ResourcePoolConfig{" +
", maxTotal=" + maxTotal +
public static class Builder {
private static final int MAX_TOTAL = 8;
private static final int MAX_IDLE = 8;
private static final int MIN_IDLE = 0;
private int maxTotal = MAX_TOTAL;
private int maxIdle = MAX_IDLE;
private int minIdle = MIN_IDLE;
public ResourcePoolConfig build() {
if (this.name == null || name == "") {
throw new IllegalArgumentException("name属性必填");
if (this.minIdle > this.maxIdle) {
throw new IllegalArgumentException("配置参数不合法");
return new ResourcePoolConfig(this);
public Builder name(String name) {
public Builder maxTotal(int maxTotal) {
this.maxTotal = maxTotal;
public Builder maxIdle(int maxIdle) {
public Builder minIdle(int minIdle) {
public static void main(String[] args) {
ResourcePoolConfig config = new Builder()
ResourcePoolConfig mysql = new ResourcePoolConfig.Builder().name("mysql").maxTotal(15).maxIdle(5).minIdle(20).build();
System.out.println(config);
System.out.println(mysql);
