测试代码

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 = ""
obj.(*MyPoolObject).Print() pool.ReturnObject(obj)
}

golang的连接池例子的更多相关文章

  1. Golang 通用连接池库 Golang-Pool

    Golang 实现的连接池 功能: * 连接池中连接类型为interface{},使得更加通用 * 链接的最大空闲时间,超时的链接将关闭丢弃,可避免空闲时链接自动失效问题 * 使用channel处理池 ...

  2. Golang SQL连接池梳理

    目录 一.如何理解数据库连接 二.连接池的工作原理 三.database/sql包结构 四.三个重要的结构体 4.1.DB 4.2.driverConn 4.3.Conn 五.流程梳理 5.1.先获取 ...

  3. golang redis连接池使用方法

    package main import ( "fmt" "github.com/garyburd/redigo/redis" ) var pool *redis ...

  4. golang mgo的mongo连接池设置:必须手动加上maxPoolSize

    本司礼物系统使用了golang的 mongo库 mgo,中间踩了一些坑,总结下避免大家再踩坑 golang的mgo库说明里是说明了开启连接复用的,但观察实验发现,这并没有根本实现连接的控制,连接复用仅 ...

  5. Tomcat+Oracle配置连接池的例子

    我这有一个Tomcat+Oracle连接池的例子,放上来和大家分享一下. Tomcat +Oracle  连接池配置   Author: Kenneth.Leaf@GalaxySoft Date: / ...

  6. [Go] golang实现mysql连接池

    golang中连接mysql数据库,需要使用一个第三方类库github.com/go-sql-driver/mysql,在这个类库中就实现了mysql的连接池,并且只需要设置两个参数就可以实现 一般连 ...

  7. 连接池的实现 redis例子

    # -*- encoding:utf-8 -*- # import pymysql # # conn = pymysql.connect(host="127.0.0.1", por ...

  8. golang 创建一个简单的连接池,减少频繁的创建与关闭

    一.连接池的描述图片如下: 二.连接池代码如下: package main; import ( "time" "sync" "errors" ...

  9. Golang 连接 MongoDB使用连接池

    可以免费试用 MongoDB ,500MB 平时做测试没有问题啦,连接数据库可能因为网络有点慢,但是我们是测试啊,不在乎这点吧~ 这是怎么申请试用版的博客,感谢这位大佬.注册好用起来很方便~ 传送门 ...

随机推荐

  1. 232. Implement Queue using Stacks

    Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...

  2. JS网址正则验证

    function IsURL(str_url){ var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9 ...

  3. System.Web.UI.ScriptManager.RegisterStartupScript(语句末尾加分号,不然可能会造成语句不执行)

    System.Web.UI.ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "testKey", &q ...

  4. SQLServer如何用T—SQL命令查询一个数据库中有哪些表

    1.查询SQL中的所有表: Select TABLE_NAME FROM 数据库名称.INFORMATION_SCHEMA.TABLES Where TABLE_TYPE='BASE TABLE' 执 ...

  5. 准备开始自己搞企业管理软件,从openerp入手

    公司运行了半年多,人还比较少,只用了一些即时通讯工具,还有svn等基本的工具 记账用的是gnucash 其他的管理急需相应的软件,找了很长时间也没有合适的 想了想,还是从开源的openerp odoo ...

  6. Codeforces Round #116 (Div. 2, ACM-ICPC Rules)

    Codeforces Round #116 (Div. 2, ACM-ICPC Rules) 代码 Codeforces Round #116 (Div. 2, ACM-ICPC Rules) A. ...

  7. 课堂所讲整理:输入输出流(I/O)

    package org.hanqi.ex; import java.io.*; public class TestFile { public static void main(String[] arg ...

  8. OOP作业

    1,定义一个水果类(fruit),水果类中的有[属性]:颜色(color).价格(price).重量(weigth),再定义一个<测试类>,创建一个苹果(apple)的对象, 颜色是&qu ...

  9. 黑马程序员——JAVA基础之简述 类的封装

    ------- android培训.java培训.期待与您交流! ---------- 类的封装(Encapsulation)  封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 封装优 ...

  10. Learn python the hard way. python test program 2016.04.27

    # this will not be printed in python ! print "I could have code like this." # and the comm ...