From 1333e005d36e591fe24defb314be362f6ad8463f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 26 Jun 2024 21:39:12 +0800 Subject: [PATCH] 1 --- dbpool.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbpool.go b/dbpool.go index 26113d1..2a00823 100644 --- a/dbpool.go +++ b/dbpool.go @@ -38,7 +38,7 @@ func (this *dbPool) unInit() { } func (this *dbPool) RegisterDataSource(name string, host string, port int32, - user string, passwd string, dataBase string, size int32) { + user string, passwd string, dataBase string, size int32, maxOpenConns int32, maxIdleConns int32) { this.lock.Lock() defer this.lock.Unlock() var head *q5.ListHead @@ -48,10 +48,16 @@ func (this *dbPool) RegisterDataSource(name string, host string, port int32, head = q5.NewListHead() this.dataSourceHash[name] = head } + if maxOpenConns <= 0 { + maxOpenConns = 1 + } + if maxIdleConns <= 0 { + maxIdleConns = 1 + } for i := int32(0); i < size; i++ { ds := dataSource{} ds.name = name - ds.conn = q5.NewMysql(host, port, user, passwd, dataBase) + ds.conn = q5.NewMysql(host, port, user, passwd, dataBase, maxOpenConns, maxIdleConns) ds.entry.Init(&ds) head.AddTail(&ds.entry) err := ds.conn.Open()