- 授权协议: Apache
- 开发语言: Google Go
- 操作系统: 跨平台
- 软件首页: https://github.com/jolestar/go-commons-pool
- 软件文档: http://jolestar.com/go-commons-pool-and-go-concurrent/
软件介绍
Go Commons Pool 是用 Go 实现的对象池,直接翻译自 Java 版的 Apache Commons Pool.
示例代码:
//use create func
pool := NewObjectPoolWithDefaultConfig(NewPooledObjectFactorySimple(
func() (interface{}, error) {
return &MyPoolObject{}, nil
}))
obj, _ := pool.BorrowObject()
pool.ReturnObject(obj)
//use custom Object factory
type MyObjectFactory struct {
}
func (this *MyObjectFactory) MakeObject() (*PooledObject, error) {
return NewPooledObject(&MyPoolObject{}), nil
}
func (this *MyObjectFactory) DestroyObject(object *PooledObject) error {
//do destroy
return nil
}
func (this *MyObjectFactory) ValidateObject(object *PooledObject) bool {
//do validate
return true
}
func (this *MyObjectFactory) ActivateObject(object *PooledObject) error {
//do activate
return nil
}
func (this *MyObjectFactory) PassivateObject(object *PooledObject) error {
//do passivate
return nil
}
pool := NewObjectPoolWithDefaultConfig(new(MyObjectFactory))
obj, _ := pool.BorrowObject()
pool.ReturnObject(obj)
Go语言学习笔记
雨痕 / 电子工业出版社 / 2016-6 / 89
作为时下流行的一种系统编程语言,Go 简单易学,性能很好,且支持各类主流平台。已有大量项目采用 Go 编写,这其中就包括 Docker 等明星作品,其开发和执行效率早已被证明。本书经四年多逐步完善,内容覆盖了语言、运行时、性能优化、工具链等各层面知识。且内容经大量读者反馈和校对,没有明显的缺陷和错误。上卷细致解析了语言规范相关细节,便于读者深入理解语言相关功能的使用方法和注意事项。下卷则对运行时源......一起来看看 《Go语言学习笔记》 这本书的介绍吧!
