# Pond: Golang 通用对象池

DevFeed: [Pond: Golang 通用对象池](<https://devfeed.tech/articles/pond-golang-40983.md>)

Original publisher: [Read original article](<https://blog.joway.io/posts/golang-common-pool/>)

Author: Joway

Published: 2021-01-23T00:00:00Z

Content type: tutorial

Language: zh

Sources: [Random Thoughts](<https://devfeed.tech/sources/random-thoughts.md>)

Topics: [context](<https://devfeed.tech/topics/context.md>), [return](<https://devfeed.tech/topics/return.md>)

Tags: [context](<https://devfeed.tech/tags/context.md>), [golang](<https://devfeed.tech/tags/golang.md>), [hive](<https://devfeed.tech/tags/hive.md>), [return](<https://devfeed.tech/tags/return.md>), [tech](<https://devfeed.tech/tags/tech.md>), [worker](<https://devfeed.tech/tags/worker.md>)

## AI overview

This tutorial introduces Pond, a reusable Go object-pool library for shared resources such as RPC clients, database connections, large objects, and worker pools. It covers capacity limits, object validation, eviction strategies, pre-creation, idle-time controls, and timeout cancellation using context, and shows how Pond can support goroutine pools through Hive.

## Source excerpt

为什么需要通用对象池 在实际生产环境中，我们经常会遇到需要多线程共享同一堆对象的场景，例如常见的RPC、数据库连接池，大内存对象池，以及线程池等。这些池化对象的需求其实有很多重叠的地方，主要分以下几个方面： 基础设置： 最大容量 创建/校验/删除对象的回调方法 申请对象时，已满时是否阻塞 多重驱逐策略： 驱逐闲置对象 驱逐无效对象 预创建对象 为避免重复编码，所以设计了 Pond 这样一个能够支撑多种使用场景的通用对象池。另外，在 Pond 的基础上，还实现了 Goroutine 池库： Hive。