Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //看了恶俗的borrow,看到return就轻松多了,
  2. //把对象置为空闲状态
  3. _factory.passivateObject(obj);
  4.  
  5. // Add instance to pool if there is room and it has passed validation
  6. boolean doAllocate = false;
  7. synchronized (this) {
  8.     if (isClosed()) {
  9.         //检查是否关闭
  10.         shouldDestroy = true;
  11.     } else {
  12.         if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) {
  13.             //检查空闲的对象是否达到maxIdle
  14.             shouldDestroy = true;
  15.         } else if(success) {
  16.             // borrowObject always takes the first element from the queue,
  17.             // so for LIFO, push on top, FIFO add to end
  18.             if (_lifo) {
  19.                 //后入先出,加到队列头部
  20.                 _pool.addFirst(new ObjectTimestampPair(obj));
  21.             } else {
  22.                 //先入先出加到队列尾部
  23.                 _pool.addLast(new ObjectTimestampPair(obj));
  24.             }
  25.             if (decrementNumActive) {
  26.                 _numActive--;
  27.             }
  28.             doAllocate = true;
  29.         }
  30.     }
  31. }
  32. //处理请求队列,为等待的请求分配对象。
  33. if (doAllocate) {
  34.     allocate();
  35. }