This commit is contained in:
aozhiwei 2024-06-26 21:39:12 +08:00
parent cc296565ec
commit 1333e005d3

View File

@ -38,7 +38,7 @@ func (this *dbPool) unInit() {
} }
func (this *dbPool) RegisterDataSource(name string, host string, port int32, 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() this.lock.Lock()
defer this.lock.Unlock() defer this.lock.Unlock()
var head *q5.ListHead var head *q5.ListHead
@ -48,10 +48,16 @@ func (this *dbPool) RegisterDataSource(name string, host string, port int32,
head = q5.NewListHead() head = q5.NewListHead()
this.dataSourceHash[name] = head this.dataSourceHash[name] = head
} }
if maxOpenConns <= 0 {
maxOpenConns = 1
}
if maxIdleConns <= 0 {
maxIdleConns = 1
}
for i := int32(0); i < size; i++ { for i := int32(0); i < size; i++ {
ds := dataSource{} ds := dataSource{}
ds.name = name 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) ds.entry.Init(&ds)
head.AddTail(&ds.entry) head.AddTail(&ds.entry)
err := ds.conn.Open() err := ds.conn.Open()