1 16 17 package org.apache.commons.pool.impl; 18 19 import java.util.Iterator ; 20 import java.util.NoSuchElementException ; 21 22 import org.apache.commons.collections.CursorableLinkedList; 23 import org.apache.commons.pool.BaseObjectPool; 24 import org.apache.commons.pool.ObjectPool; 25 import org.apache.commons.pool.PoolableObjectFactory; 26 27 124 public class GenericObjectPool extends BaseObjectPool implements ObjectPool { 125 126 128 137 public static final byte WHEN_EXHAUSTED_FAIL = 0; 138 139 151 public static final byte WHEN_EXHAUSTED_BLOCK = 1; 152 153 162 public static final byte WHEN_EXHAUSTED_GROW = 2; 163 164 169 public static final int DEFAULT_MAX_IDLE = 8; 170 171 177 public static final int DEFAULT_MIN_IDLE = 0; 178 179 183 public static final int DEFAULT_MAX_ACTIVE = 8; 184 185 192 public static final byte DEFAULT_WHEN_EXHAUSTED_ACTION = WHEN_EXHAUSTED_BLOCK; 193 194 203 public static final long DEFAULT_MAX_WAIT = -1L; 204 205 210 public static final boolean DEFAULT_TEST_ON_BORROW = false; 211 212 217 public static final boolean DEFAULT_TEST_ON_RETURN = false; 218 219 226 public static final boolean DEFAULT_TEST_WHILE_IDLE = false; 227 228 233 public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L; 234 235 243 public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3; 244 245 250 public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L; 251 252 257 public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1; 258 259 261 264 public GenericObjectPool() { 265 this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 266 } 267 268 272 public GenericObjectPool(PoolableObjectFactory factory) { 273 this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 274 } 275 276 281 public GenericObjectPool(PoolableObjectFactory factory, GenericObjectPool.Config config) { 282 this(factory,config.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.minIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle); 283 } 284 285 290 public GenericObjectPool(PoolableObjectFactory factory, int maxActive) { 291 this(factory,maxActive,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 292 } 293 294 301 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait) { 302 this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 303 } 304 305 314 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) { 315 this(factory,maxActive,whenExhaustedAction,maxWait,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 316 } 317 318 326 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) { 327 this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 328 } 329 330 340 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) { 341 this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); 342 } 343 344 358 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) { 359 this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle); 360 } 361 362 377 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) { 378 this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); 379 } 380 381 397 public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis) { 398 _factory = factory; 399 _maxActive = maxActive; 400 switch(whenExhaustedAction) { 401 case WHEN_EXHAUSTED_BLOCK: 402 case WHEN_EXHAUSTED_FAIL: 403 case WHEN_EXHAUSTED_GROW: 404 _whenExhaustedAction = whenExhaustedAction; 405 break; 406 default: 407 throw new IllegalArgumentException ("whenExhaustedAction " + whenExhaustedAction + " not recognized."); 408 } 409 _maxWait = maxWait; 410 _maxIdle = maxIdle; 411 _minIdle = minIdle; 412 _testOnBorrow = testOnBorrow; 413 _testOnReturn = testOnReturn; 414 _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; 415 _numTestsPerEvictionRun = numTestsPerEvictionRun; 416 _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; 417 _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; 418 _testWhileIdle = testWhileIdle; 419 420 _pool = new CursorableLinkedList(); 421 startEvictor(_timeBetweenEvictionRunsMillis); 422 } 423 424 426 428 433 public synchronized int getMaxActive() { 434 return _maxActive; 435 } 436 437 443 public synchronized void setMaxActive(int maxActive) { 444 _maxActive = maxActive; 445 notifyAll(); 446 } 447 448 456 public synchronized byte getWhenExhaustedAction() { 457 return _whenExhaustedAction; 458 } 459 460 470 public synchronized void setWhenExhaustedAction(byte whenExhaustedAction) { 471 switch(whenExhaustedAction) { 472 case WHEN_EXHAUSTED_BLOCK: 473 case WHEN_EXHAUSTED_FAIL: 474 case WHEN_EXHAUSTED_GROW: 475 _whenExhaustedAction = whenExhaustedAction; 476 notifyAll(); 477 break; 478 default: 479 throw new IllegalArgumentException ("whenExhaustedAction " + whenExhaustedAction + " not recognized."); 480 } 481 } 482 483 484 498 public synchronized long getMaxWait() { 499 return _maxWait; 500 } 501 502 516 public synchronized void setMaxWait(long maxWait) { 517 _maxWait = maxWait; 518 notifyAll(); 519 } 520 521 526 public synchronized int getMaxIdle() { 527 return _maxIdle; 528 } 529 530 537 public synchronized void setMaxIdle(int maxIdle) { 538 _maxIdle = maxIdle; 539 notifyAll(); 540 } 541 542 550 public synchronized void setMinIdle(int minIdle) { 551 _minIdle = minIdle; 552 notifyAll(); 553 } 554 555 563 public synchronized int getMinIdle() { 564 return _minIdle; 565 } 566 567 577 public synchronized boolean getTestOnBorrow() { 578 return _testOnBorrow; 579 } 580 581 591 public synchronized void setTestOnBorrow(boolean testOnBorrow) { 592 _testOnBorrow = testOnBorrow; 593 } 594 595 603 public synchronized boolean getTestOnReturn() { 604 return _testOnReturn; 605 } 606 607 615 public synchronized void setTestOnReturn(boolean testOnReturn) { 616 _testOnReturn = testOnReturn; 617 } 618 619 627 public synchronized long getTimeBetweenEvictionRunsMillis() { 628 return _timeBetweenEvictionRunsMillis; 629 } 630 631 639 public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) { 640 _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; 641 startEvictor(_timeBetweenEvictionRunsMillis); 642 } 643 644 651 public synchronized int getNumTestsPerEvictionRun() { 652 return _numTestsPerEvictionRun; 653 } 654 655 666 public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { 667 _numTestsPerEvictionRun = numTestsPerEvictionRun; 668 } 669 670 678 public synchronized long getMinEvictableIdleTimeMillis() { 679 return _minEvictableIdleTimeMillis; 680 } 681 682 692 public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) { 693 _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; 694 } 695 696 704 public synchronized long getSoftMinEvictableIdleTimeMillis() { 705 return _softMinEvictableIdleTimeMillis; 706 } 707 708 718 public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) { 719 _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; 720 } 721 722 731 public synchronized boolean getTestWhileIdle() { 732 return _testWhileIdle; 733 } 734 735 744 public synchronized void setTestWhileIdle(boolean testWhileIdle) { 745 _testWhileIdle = testWhileIdle; 746 } 747 748 752 public synchronized void setConfig(GenericObjectPool.Config conf) { 753 setMaxIdle(conf.maxIdle); 754 setMinIdle(conf.minIdle); 755 setMaxActive(conf.maxActive); 756 setMaxWait(conf.maxWait); 757 setWhenExhaustedAction(conf.whenExhaustedAction); 758 setTestOnBorrow(conf.testOnBorrow); 759 setTestOnReturn(conf.testOnReturn); 760 setTestWhileIdle(conf.testWhileIdle); 761 setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); 762 setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); 763 setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); 764 notifyAll(); 765 } 766 767 769 public Object borrowObject() throws Exception { 770 long starttime = System.currentTimeMillis(); 771 boolean newlyCreated = false; 772 for(;;) { 773 ObjectTimestampPair pair = null; 774 775 synchronized(this) { 776 assertOpen(); 777 778 try { 780 pair = (ObjectTimestampPair)(_pool.removeFirst()); 781 } catch(NoSuchElementException e) { 782 ; 783 } 784 785 if(null == pair) { 787 if(_maxActive < 0 || _numActive < _maxActive) { 790 } else { 792 switch(_whenExhaustedAction) { 794 case WHEN_EXHAUSTED_GROW: 795 break; 797 case WHEN_EXHAUSTED_FAIL: 798 throw new NoSuchElementException ("Pool exhausted"); 799 case WHEN_EXHAUSTED_BLOCK: 800 try { 801 if(_maxWait <= 0) { 802 wait(); 803 } else { 804 wait(_maxWait); 805 } 806 } catch(InterruptedException e) { 807 } 809 if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { 810 throw new NoSuchElementException ("Timeout waiting for idle object"); 811 } else { 812 continue; } 814 default: 815 throw new IllegalArgumentException ("WhenExhaustedAction property " + _whenExhaustedAction + " not recognized."); 816 } 817 } 818 } 819 _numActive++; 820 } 822 if(null == pair) { 824 try { 825 Object obj = _factory.makeObject(); 826 pair = new ObjectTimestampPair(obj); 827 newlyCreated = true; 828 } 829 catch (Throwable e) { 830 synchronized(this) { 832 _numActive--; 833 notifyAll(); 834 } 835 if (e instanceof Exception ) { 836 throw (Exception ) e; 837 } else if (e instanceof Error ) { 838 throw (Error ) e; 839 } else { 840 throw new Exception (e); 841 } 842 } 843 } 844 845 try { 847 _factory.activateObject(pair.value); 848 if(_testOnBorrow && !_factory.validateObject(pair.value)) { 849 throw new Exception ("ValidateObject failed"); 850 } 851 return pair.value; 852 } 853 catch (Throwable e) { 854 synchronized(this) { 856 _numActive--; 857 notifyAll(); 858 } 859 try { 860 _factory.destroyObject(pair.value); 861 } 862 catch (Throwable e2) { 863 } 865 if(newlyCreated) { 866 throw new NoSuchElementException ("Could not create a validated object, cause: " + e.getMessage()); 867 } 868 else { 869 continue; } 871 } 872 } 873 } 874 875 public void invalidateObject(Object obj) throws Exception { 876 assertOpen(); 877 try { 878 _factory.destroyObject(obj); 879 } 880 finally { 881 synchronized(this) { 882 _numActive--; 883 notifyAll(); } 885 } 886 } 887 888 public synchronized void clear() { 889 assertOpen(); 890 for(Iterator it = _pool.iterator(); it.hasNext(); ) { 891 try { 892 _factory.destroyObject(((ObjectTimestampPair)(it.next())).value); 893 } catch(Exception e) { 894 } 896 it.remove(); 897 } 898 _pool.clear(); 899 notifyAll(); } 901 902 public synchronized int getNumActive() { 903 assertOpen(); 904 return _numActive; 905 } 906 907 public synchronized int getNumIdle() { 908 assertOpen(); 909 return _pool.size(); 910 } 911 912 public void returnObject(Object obj) throws Exception { 913 assertOpen(); 914 addObjectToPool(obj, true); 915 } 916 917 private void addObjectToPool(Object obj, boolean decrementNumActive) throws Exception { 918 boolean success = true; 919 if(_testOnReturn && !(_factory.validateObject(obj))) { 920 success = false; 921 } else { 922 try { 923 _factory.passivateObject(obj); 924 } catch(Exception e) { 925 success = false; 926 } 927 } 928 929 boolean shouldDestroy = !success; 930 931 synchronized(this) { 932 if (decrementNumActive) { 933 _numActive--; 934 } 935 if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { 936 shouldDestroy = true; 937 } else if(success) { 938 _pool.addFirst(new ObjectTimestampPair(obj)); 939 } 940 notifyAll(); } 942 943 if(shouldDestroy) { 944 try { 945 _factory.destroyObject(obj); 946 } catch(Exception e) { 947 } 949 } 950 } 951 952 public synchronized void close() throws Exception { 953 clear(); 954 _pool = null; 955 _factory = null; 956 if(null != _evictionCursor) { 957 _evictionCursor.close(); 958 _evictionCursor = null; 959 } 960 startEvictor(-1L); 961 super.close(); 962 } 963 964 public synchronized void setFactory(PoolableObjectFactory factory) throws IllegalStateException { 965 assertOpen(); 966 if(0 < getNumActive()) { 967 throw new IllegalStateException ("Objects are already active"); 968 } else { 969 clear(); 970 _factory = factory; 971 } 972 } 973 974 public synchronized void evict() throws Exception { 975 assertOpen(); 976 if(!_pool.isEmpty()) { 977 if(null == _evictionCursor) { 978 _evictionCursor = (_pool.cursor(_pool.size())); 979 } else if(!_evictionCursor.hasPrevious()) { 980 _evictionCursor.close(); 981 _evictionCursor = (_pool.cursor(_pool.size())); 982 } 983 for(int i=0,m=getNumTests();i<m;i++) { 984 if(!_evictionCursor.hasPrevious()) { 985 _evictionCursor.close(); 986 _evictionCursor = (_pool.cursor(_pool.size())); 987 } else { 988 boolean removeObject = false; 989 ObjectTimestampPair pair = (ObjectTimestampPair)(_evictionCursor.previous()); 990 long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; 991 if ((_minEvictableIdleTimeMillis > 0) 992 && (idleTimeMilis > _minEvictableIdleTimeMillis)) { 993 removeObject = true; 994 } else if ((_softMinEvictableIdleTimeMillis > 0) 995 && (idleTimeMilis > _softMinEvictableIdleTimeMillis) 996 && (getNumIdle() > getMinIdle())) { 997 removeObject = true; 998 } else if(_testWhileIdle) { 999 boolean active = false; 1000 try { 1001 _factory.activateObject(pair.value); 1002 active = true; 1003 } catch(Exception e) { 1004 removeObject=true; 1005 } 1006 if(active) { 1007 if(!_factory.validateObject(pair.value)) { 1008 removeObject=true; 1009 } else { 1010 try { 1011 _factory.passivateObject(pair.value); 1012 } catch(Exception e) { 1013 removeObject=true; 1014 } 1015 } 1016 } 1017 } 1018 if(removeObject) { 1019 try { 1020 _evictionCursor.remove(); 1021 _factory.destroyObject(pair.value); 1022 } catch(Exception e) { 1023 ; } 1025 } 1026 } 1027 } 1028 } } 1030 1031 1035 private void ensureMinIdle() throws Exception { 1036 int objectDeficit = calculateDeficit(); 1042 for ( int j = 0 ; j < objectDeficit && calculateDeficit() > 0 ; j++ ) { 1043 addObject(); 1044 } 1045 } 1046 1047 private synchronized int calculateDeficit() { 1048 int objectDeficit = getMinIdle() - getNumIdle(); 1049 if (_maxActive > 0) { 1050 int growLimit = Math.max(0, getMaxActive() - getNumActive() - getNumIdle()); 1051 objectDeficit = Math.min(objectDeficit, growLimit); 1052 } 1053 return objectDeficit; 1054 } 1055 1056 1060 public void addObject() throws Exception { 1061 Object obj = _factory.makeObject(); 1062 addObjectToPool(obj, false); 1063 } 1064 1065 1067 1072 protected synchronized void startEvictor(long delay) { 1073 if(null != _evictor) { 1074 _evictor.cancel(); 1075 _evictor = null; 1076 } 1077 if(delay > 0) { 1078 _evictor = new Evictor(delay); 1079 Thread t = new Thread (_evictor); 1080 t.setDaemon(true); 1081 t.start(); 1082 } 1083 } 1084 1085 synchronized String debugInfo() { 1086 StringBuffer buf = new StringBuffer (); 1087 buf.append("Active: ").append(getNumActive()).append("\n"); 1088 buf.append("Idle: ").append(getNumIdle()).append("\n"); 1089 buf.append("Idle Objects:\n"); 1090 Iterator it = _pool.iterator(); 1091 long time = System.currentTimeMillis(); 1092 while(it.hasNext()) { 1093 ObjectTimestampPair pair = (ObjectTimestampPair)(it.next()); 1094 buf.append("\t").append(pair.value).append("\t").append(time - pair.tstamp).append("\n"); 1095 } 1096 return buf.toString(); 1097 } 1098 1099 private int getNumTests() { 1100 if(_numTestsPerEvictionRun >= 0) { 1101 return _numTestsPerEvictionRun; 1102 } else { 1103 return(int)(Math.ceil((double)_pool.size()/Math.abs((double)_numTestsPerEvictionRun))); 1104 } 1105 } 1106 1107 1109 1112 class ObjectTimestampPair { 1113 Object value; 1114 long tstamp; 1115 1116 ObjectTimestampPair(Object val) { 1117 this(val,System.currentTimeMillis()); 1118 } 1119 1120 ObjectTimestampPair(Object val, long time) { 1121 value = val; 1122 tstamp = time; 1123 } 1124 } 1125 1126 1130 class Evictor implements Runnable { 1131 private boolean _cancelled = false; 1132 private long _delay = 0L; 1133 1134 public Evictor(long delay) { 1135 _delay = delay; 1136 } 1137 1138 void cancel() { 1139 _cancelled = true; 1140 } 1141 1142 public void run() { 1143 while(!_cancelled) { 1144 try { 1145 Thread.sleep(_delay); 1146 } catch(Exception e) { 1147 } 1149 try { 1150 evict(); 1151 } catch(Exception e) { 1152 } 1154 try { 1155 ensureMinIdle(); 1156 } catch(Exception e) { 1157 } 1159 } 1160 synchronized(GenericObjectPool.this) { 1161 if(null != _evictionCursor) { 1162 _evictionCursor.close(); 1163 _evictionCursor = null; 1164 } 1165 } 1166 } 1167 1168 } 1169 1170 1176 public static class Config { 1177 public int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE; 1178 public int minIdle = GenericObjectPool.DEFAULT_MIN_IDLE; 1179 public int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE; 1180 public long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT; 1181 public byte whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION; 1182 public boolean testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW; 1183 public boolean testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN; 1184 public boolean testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE; 1185 public long timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; 1186 public int numTestsPerEvictionRun = GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN; 1187 public long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; 1188 public long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; 1189 } 1190 1191 1193 1198 private int _maxIdle = DEFAULT_MAX_IDLE; 1199 1200 1205 private int _minIdle = DEFAULT_MIN_IDLE; 1206 1207 1212 private int _maxActive = DEFAULT_MAX_ACTIVE; 1213 1214 1230 private long _maxWait = DEFAULT_MAX_WAIT; 1231 1232 1244 private byte _whenExhaustedAction = DEFAULT_WHEN_EXHAUSTED_ACTION; 1245 1246 1257 private boolean _testOnBorrow = DEFAULT_TEST_ON_BORROW; 1258 1259 1268 private boolean _testOnReturn = DEFAULT_TEST_ON_RETURN; 1269 1270 1281 private boolean _testWhileIdle = DEFAULT_TEST_WHILE_IDLE; 1282 1283 1292 private long _timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; 1293 1294 1307 private int _numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN; 1308 1309 1321 private long _minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; 1322 1323 1334 private long _softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS; 1335 1336 1337 private CursorableLinkedList _pool = null; 1338 1339 1340 private PoolableObjectFactory _factory = null; 1341 1342 1346 private int _numActive = 0; 1347 1348 1351 private Evictor _evictor = null; 1352 1353 private CursorableLinkedList.Cursor _evictionCursor = null; 1354} 1355 | Popular Tags |