@@ -20,7 +20,7 @@ final class PooledConnectionQueue {
2020 /**
2121 * A 'circular' buffer designed specifically for free connections.
2222 */
23- private final FreeConnectionBuffer freeList ;
23+ private final ConnectionBuffer buffer ;
2424 /**
2525 * A 'slots' buffer designed specifically for busy connections.
2626 * Fast add remove based on slot id.
@@ -75,13 +75,13 @@ final class PooledConnectionQueue {
7575 this .maxAgeMillis = pool .maxAgeMillis ();
7676 this .validateStaleMillis = pool .validateStaleMillis ();
7777 this .busyList = new BusyConnectionBuffer (maxSize , 20 );
78- this .freeList = new FreeConnectionBuffer ();
78+ this .buffer = new ConnectionBuffer ();
7979 this .lock = new ReentrantLock (false );
8080 this .notEmpty = lock .newCondition ();
8181 }
8282
8383 private PoolStatus createStatus () {
84- return new Status (minSize , maxSize , freeList . size (), busyList .size (), waitingThreads , highWaterMark ,
84+ return new Status (minSize , maxSize , buffer . freeSize (), busyList .size (), waitingThreads , highWaterMark ,
8585 waitCount , hitCount , totalAcquireNanos , maxAcquireNanos );
8686 }
8787
@@ -126,7 +126,7 @@ void setMaxSize(int maxSize) {
126126 }
127127
128128 private int totalConnections () {
129- return freeList . size () + busyList .size ();
129+ return buffer . freeSize () + busyList .size ();
130130 }
131131
132132 void ensureMinimumConnections () throws SQLException {
@@ -135,7 +135,7 @@ void ensureMinimumConnections() throws SQLException {
135135 int add = minSize - totalConnections ();
136136 if (add > 0 ) {
137137 for (int i = 0 ; i < add ; i ++) {
138- freeList . add (pool .createConnectionForQueue (connectionId ++));
138+ buffer . addFree (pool .createConnectionForQueue (connectionId ++));
139139 }
140140 notEmpty .signal ();
141141 }
@@ -156,7 +156,7 @@ void returnPooledConnection(PooledConnection c, boolean forceClose) {
156156 if (forceClose || c .shouldTrimOnReturn (lastResetTime , maxAgeMillis )) {
157157 c .closeConnectionFully (false );
158158 } else {
159- freeList . add (c );
159+ buffer . addFree (c );
160160 notEmpty .signal ();
161161 }
162162 } finally {
@@ -165,10 +165,11 @@ void returnPooledConnection(PooledConnection c, boolean forceClose) {
165165 }
166166
167167 private PooledConnection extractFromFreeList () {
168- if (freeList .isEmpty ()) {
168+
169+ PooledConnection c = buffer .popFree ();
170+ if (c == null ) {
169171 return null ;
170172 }
171- final PooledConnection c = freeList .remove ();
172173 if (validateStaleMillis > 0 && staleEviction (c )) {
173174 c .closeConnectionFully (false );
174175 return null ;
@@ -291,7 +292,7 @@ private PooledConnection _obtainConnectionWaitLoop() throws SQLException, Interr
291292
292293 try {
293294 nanos = notEmpty .awaitNanos (nanos );
294- if (! freeList . isEmpty ()) {
295+ if (buffer . hasFreeConnections ()) {
295296 // successfully waited
296297 return extractFromFreeList ();
297298 }
@@ -373,20 +374,20 @@ void trim(long maxInactiveMillis, long maxAgeMillis) {
373374 private boolean trimInactiveConnections (long maxInactiveMillis , long maxAgeMillis ) {
374375 final long createdSince = (maxAgeMillis == 0 ) ? 0 : System .currentTimeMillis () - maxAgeMillis ;
375376 final int trimmedCount ;
376- if (freeList . size () > minSize ) {
377+ if (buffer . freeSize () > minSize ) {
377378 // trim on maxInactive and maxAge
378379 long usedSince = System .currentTimeMillis () - maxInactiveMillis ;
379- trimmedCount = freeList .trim (minSize , usedSince , createdSince );
380+ trimmedCount = buffer .trim (minSize , usedSince , createdSince );
380381 } else if (createdSince > 0 ) {
381382 // trim only on maxAge
382- trimmedCount = freeList .trim (0 , createdSince , createdSince );
383+ trimmedCount = buffer .trim (0 , createdSince , createdSince );
383384 } else {
384385 trimmedCount = 0 ;
385386 }
386387 if (trimmedCount > 0 && Log .isLoggable (DEBUG )) {
387388 Log .debug ("DataSource [{0}] trimmed [{1}] inactive connections. New size[{2}]" , name , trimmedCount , totalConnections ());
388389 }
389- return trimmedCount > 0 && freeList . size () < minSize ;
390+ return trimmedCount > 0 && buffer . freeSize () < minSize ;
390391 }
391392
392393 /**
@@ -395,7 +396,7 @@ private boolean trimInactiveConnections(long maxInactiveMillis, long maxAgeMilli
395396 private void closeFreeConnections (boolean logErrors ) {
396397 lock .lock ();
397398 try {
398- freeList . closeAll (logErrors );
399+ buffer . closeAllFree (logErrors );
399400 } finally {
400401 lock .unlock ();
401402 }
0 commit comments