// ReturnObject return an instance to the pool. By contract, object
// must have been obtained using BorrowObject()
ReturnObject return an instance to the pool. By contract, object
must have been obtained using BorrowObject()
// ReturnObject return an instance to the pool . By contract object // must have been obtained using BorrowObject ()
func (pool *ObjectPool) ReturnObject(object interface{}) error {
	if object == nil {
		return errors.New("object is nil")
	}
	p, ok := pool.allObjects.Get(object).(*PooledObject)
	if !ok {
		if !pool.isAbandonedConfig() {
			return NewIllegalStateErr(
				"Returned object not currently part of pool")
		}
		return nil 
	}
	p.lock.Lock()
	state := p.state
	if state != StateAllocated {
		p.lock.Unlock()
		return NewIllegalStateErr(
			"Object has already been returned to pool or is invalid")
	}
	p.markReturning() 
	p.lock.Unlock()
	activeTime := p.GetActiveTimeMillis()
	if pool.Config.TestOnReturn {
		if !pool.factory.ValidateObject(p) {
			pool.destroy(p)
			pool.ensureIdle(1, false)
			pool.updateStatsReturn(activeTime)
			return nil
		}
	}
	err := pool.factory.PassivateObject(p)
	if err != nil {
		pool.destroy(p)
		pool.ensureIdle(1, false)
		pool.updateStatsReturn(activeTime)
		return nil
	}
	if !p.Deallocate() {
		return NewIllegalStateErr("Object has already been returned to pool or is invalid")
	}
	maxIdleSave := pool.Config.MaxIdle
	if pool.IsClosed() || maxIdleSave > -1 && maxIdleSave <= pool.idleObjects.Size() {
		pool.destroy(p)
	} else {
		if pool.Config.Lifo {
			pool.idleObjects.AddFirst(p)
		} else {
			pool.idleObjects.AddLast(p)
		}
		if pool.IsClosed() {
			pool.Clear()
		}
	}
	pool.updateStatsReturn(activeTime)
	return nil
}
func ( pool * ObjectPool ) ReturnObject ( object interface { } ) error { if object == nil { return errors . New ( " " ) } p , ok := pool . allObjects . Get ( object ) . ( * PooledObject ) if ! ok { if ! pool . isAbandonedConfig ( ) { return NewIllegalStateErr ( " " ) } return nil } p . lock . Lock ( ) state := p . state if state != StateAllocated { p . lock . Unlock ( ) return NewIllegalStateErr ( " " ) } p . markReturning ( ) p . lock . Unlock ( ) activeTime := p . GetActiveTimeMillis ( ) if pool . Config . TestOnReturn { if ! pool . factory . ValidateObject ( p ) { pool . destroy ( p ) pool . ensureIdle ( 1 , false ) pool . updateStatsReturn ( activeTime ) return nil } } err := pool . factory . PassivateObject ( p ) if err != nil { pool . destroy ( p ) pool . ensureIdle ( 1 , false ) pool . updateStatsReturn ( activeTime ) return nil } if ! p . Deallocate ( ) { return NewIllegalStateErr ( " " ) } maxIdleSave := pool . Config . MaxIdle if pool . IsClosed ( ) || maxIdleSave > - 1 && maxIdleSave <= pool . idleObjects . Size ( ) { pool . destroy ( p ) } else { if pool . Config . Lifo { pool . idleObjects . AddFirst ( p ) } else { pool . idleObjects . AddLast ( p ) } if pool . IsClosed ( ) { pool . Clear ( ) } } pool . updateStatsReturn ( activeTime ) return nil }
ReturnObject return an instance to the pool.
ReturnObject return an instance to the pool .
// Object was abandoned and removed //use unlock method markReturning() not MarkReturning // because go lock is not recursive // Keep from being marked abandoned // swallowException(e); //swallowException(e1); // swallowException(e); // Pool closed while object was being added to idle objects. // Make sure the returned object is destroyed rather than left // in the idle object pool (which would effectively be a leak)