diff --git a/g/container/gpool/gpool.go b/g/container/gpool/gpool.go index 0d9959830..bbde2db0b 100644 --- a/g/container/gpool/gpool.go +++ b/g/container/gpool/gpool.go @@ -30,6 +30,7 @@ type poolItem struct { } // 创建一个对象池,为保证执行效率,过期时间一旦设定之后无法修改 +// 注意过期时间单位为**毫秒** func New(expire int, newFunc...func() (interface{}, error)) *Pool { r := &Pool { list : glist.New(), @@ -82,13 +83,15 @@ func (p *Pool) Close() { // 超时检测循环 func (p *Pool) expireCheckingLoop() { for !p.closed.Val() { - if r := p.list.PopFront(); r != nil { - f := r.(*poolItem) - if f.expire > gtime.Millisecond() { - p.list.PushFront(f) - break + for { + if r := p.list.PopFront(); r != nil { + f := r.(*poolItem) + if f.expire > gtime.Millisecond() { + p.list.PushFront(f) + break + } } } - time.Sleep(3 * time.Second) + time.Sleep(time.Second) } } \ No newline at end of file diff --git a/geg/other/test.go b/geg/other/test.go index 8b02b1049..534c686b7 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,12 +1,17 @@ package main import ( + "gitee.com/johng/gf/g/container/gpool" "fmt" - "gitee.com/johng/gf/g/net/ghttp" + "time" ) - func main() { - r, _ := ghttp.Get("http://johng.cn") - fmt.Println(string(r.ReadAll())) + p := gpool.New(1000) + for i := 0 ; i < 100; i++ { + p.Put(i) + } + fmt.Println(p.Size()) + time.Sleep(2*time.Second) + fmt.Println(p.Size()) } \ No newline at end of file