golang的连接池例子
2016-03-02 09:36
429 查看
github.com/jolestar/go-commons-pool
测试代码
package main import ( "github.com/jolestar/go-commons-pool" "fmt" ) type MyPoolObject struct { Name string } type MyObjectFactory struct { } func (f *MyPoolObject) Print() { fmt.Println(f) } func (f *MyObjectFactory) MakeObject() (*pool.PooledObject, error) { return pool.NewPooledObject(&MyPoolObject{}), nil } func (f *MyObjectFactory) DestroyObject(object *pool.PooledObject) error { //do destroy return nil } func (f *MyObjectFactory) ValidateObject(object *pool.PooledObject) bool { //do validate return true } func (f *MyObjectFactory) ActivateObject(object *pool.PooledObject) error { //do activate return nil } func (f *MyObjectFactory) PassivateObject(object *pool.PooledObject) error { //do passivate return nil } func main() { pool := pool.NewObjectPoolWithDefaultConfig(pool.NewPooledObjectFactorySimple( func() (interface{}, error) { return &MyPoolObject{}, nil })) obj, _ := pool.BorrowObject() obj.(*MyPoolObject).Name = "1111" obj.(*MyPoolObject).Print() pool.ReturnObject(obj) }
相关文章推荐
- 原创翻译:James Whittaker系列——Google是如何测试的(3)
- 1.NSString+category
- Fcitx下的Google拼音和云拼音
- VIEWGOOD(远古)电力行业流媒体项目
- [Google EarlGrey] 0x02 API 简介
- django1.9使用django-pageination出现AttributeError错误处理
- Euclid‘s algorithm
- SGOI 海上搜索 状压DP
- Django基础——Form&Ajax篇
- 算法代码实现之堆排序,Golang(Go语言)实现
- 【CodeForces】A. Dragons
- 熟悉一下GO的AES加密库
- Django~static files
- Django中的F表达式来解决丢失修改问题
- 关于Go语言共享内存操作的小实例
- Xcode警告Category is implementing a method which will also be implemented by its primary class 处理
- POJ2195 Going Home(SPFA最小费用最大流)
- go liteIDE
- Django 路由
- django:field字段类型