Created
July 23, 2012 13:47
-
-
Save ellios/3163684 to your computer and use it in GitHub Desktop.
returnObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//看了恶俗的borrow,看到return就轻松多了, | |
//把对象置为空闲状态 | |
_factory.passivateObject(obj); | |
// Add instance to pool if there is room and it has passed validation | |
boolean doAllocate = false; | |
synchronized (this) { | |
if (isClosed()) { | |
//检查是否关闭 | |
shouldDestroy = true; | |
} else { | |
if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { | |
//检查空闲的对象是否达到maxIdle | |
shouldDestroy = true; | |
} else if(success) { | |
// borrowObject always takes the first element from the queue, | |
// so for LIFO, push on top, FIFO add to end | |
if (_lifo) { | |
//后入先出,加到队列头部 | |
_pool.addFirst(new ObjectTimestampPair(obj)); | |
} else { | |
//先入先出加到队列尾部 | |
_pool.addLast(new ObjectTimestampPair(obj)); | |
} | |
if (decrementNumActive) { | |
_numActive--; | |
} | |
doAllocate = true; | |
} | |
} | |
} | |
//处理请求队列,为等待的请求分配对象。 | |
if (doAllocate) { | |
allocate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment