fix pool bug

This commit is contained in:
Looly
2024-11-12 13:40:07 +08:00
parent efa7d433af
commit cbaf8103e9
7 changed files with 76 additions and 31 deletions

View File

@@ -20,6 +20,7 @@ import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.pool.ObjectFactory;
import org.dromara.hutool.core.pool.ObjectPool;
import org.dromara.hutool.core.pool.Poolable;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.thread.ThreadUtil;
import java.io.IOException;
@@ -117,6 +118,12 @@ public class PartitionObjectPool<T> implements ObjectPool<T> {
IoUtil.closeQuietly(this.partitions);
}
@Override
public String toString() {
return StrUtil.format("PartitionObjectPool: total: {}, idle: {}, active: {}",
getTotal(), getIdleCount(), getActiveCount());
}
/**
* 创建阻塞队列,默认为{@link ArrayBlockingQueue}<br>
* 如果需要自定义队列类型,子类重写此方法

View File

@@ -81,7 +81,7 @@ public class PoolPartition<T> implements ObjectPool<T> {
// 检查是否超过最长空闲时间
final long maxIdle = this.config.getMaxIdle();
if (maxIdle <= 0 || poolable.getIdle() <= maxIdle) {
return poolable.getRaw();
return obj;
}
}
@@ -188,11 +188,7 @@ public class PoolPartition<T> implements ObjectPool<T> {
return wrapPoolable(t);
}
@SuppressWarnings("unchecked")
private Poolable<T> wrapPoolable(final T t) {
if (t instanceof Poolable) {
return (Poolable<T>) t;
}
return new PartitionPoolable<>(t, this);
}