wake up and clean the pools if the pool has empty connection table.
186645
public void run() {
//    todo    if (logger.isDebugEnabled()) {
//            logger.debug("start running PooledDataSourceCleaner");
//        }

        state = STATE_CLEANER.RUNNING;
        while (state != STATE_CLEANER.SHUTDOWN) {
            try {
                Thread.sleep(interval * 1000);
            } catch (InterruptedException e) {
//              todo  if (logger.isDebugEnabled()) {
//                    logger.debug("Get interrupted, shutdown the PooledDataSourceCleaner");
//                }
                break;//get out if anyone interrupt
            }
            this.manager.cleanDataSources();

            //if no pool at all, going to stop itself
            if (this.manager.getDbmsPoolSize() == 0) {
//             todo   if (logger.isDebugEnabled()) {
//                    logger.debug("Empty pools, shutdown the PooledDataSourceCleaner");
//                }
                state = STATE_CLEANER.SHUTDOWN;//stop spinning
                break; //get out
            }
        }
    }
310781
def free(self, connection):
        
        LOGGER.debug('Pool %s freeing connection %s', self.id, id(connection))
        try:
            self.connection_handle(connection).free()
        except KeyError:
            raise ConnectionNotFoundError(self.id, id(connection))

        if self.idle_connections == list(self.connections.values()):
            with self._lock:
                self.idle_start = self.time_method()
        LOGGER.debug('Pool %s freed connection %s', self.id, id(connection))
1348277
protected void postConnection(ConnectionHandle handle, long statsObtainTime){

		handle.renewConnection(); // mark it as being logically "open"

		// Give an application a chance to do something with it.
		if (handle.getConnectionHook() != null){
			handle.getConnectionHook().onCheckOut(handle);
		}

		if (this.pool.closeConnectionWatch){ // a debugging tool
			this.pool.watchConnection(handle);
		}

		if (this.pool.statisticsEnabled){
			this.pool.statistics.addCumulativeConnectionWaitTime(System.nanoTime()-statsObtainTime);
		}
	}
1141541
public function wakeup()
    {
        if ($this->state === Generic::STATE_WAITING) {
            $this->ev->del();
            $this->ev->add(0);
        }
    }
1106295
public void cleanup() throws ResourceException
   {
      for (HelloWorldConnectionImpl connection : connections)
      {
         connection.setManagedConnection(null);
      }
      connections.clear();
   }
550106
public void cleanup() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "cleanup");
        }

        // Invalidate any currently associated connections
        for (Iterator iterator = _connections.iterator(); iterator.hasNext();) {

            final SibRaConnection connection = (SibRaConnection) iterator
                    .next();
            connection.invalidate();

        }

        // If we have a connection exception then we must have hit a problem with getting the
        // physical connection. We need to throw an exception here to force the destroy of this
        // managed connection else it goes in the free pool. I better solution would be to expose
        // an api that we can call on jca, this is work in progress.
        if (_connectionException != null)
        {
          //The string used here is searched for by jca so that it won't log the error
            ResourceException exception = new ResourceException("Skip logging for this failing connection");
            if (TRACE.isEventEnabled()) {
              SibTr.exception(this, TRACE, exception);
            }
            throw exception;
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "cleanup");
        }

    }
1107510
function(pool) {
    let toRemove = Math.max(1, pool.idleConnections() - opts.minimumIdle);
    while (toRemove > 0) {
      const conn = idleConnections.peek();
      --toRemove;
      if (conn && conn.lastUse + opts.idleTimeout * 1000 < Date.now()) {
        idleConnections.shift();
        conn.forceEnd().catch(err => {});
        conn.releaseWithoutError();
        continue;
      }
      break;
    }
    ensurePoolSize(pool);
  }
985603
public void start() {
        FixedSchedulerPool update = new FixedSchedulerPool(poolSize);
        if (!pool.compareAndSet(NONE, update)) {
            update.shutdown();
        }
    }
554265
static function cleanup()
    {
        $availableHandlers = eZNotificationEventFilter::availableHandlers();

        $db = eZDB::instance();
        $db->begin();
        foreach( $availableHandlers as $handler )
        {
            if ( $handler !== false )
            {
                $handler->cleanup();
            }
        }
        $db->commit();
    }
413378
private void ensureCleanStartup() {
        forceShutdown();
        ScheduledThreadPoolExecutor oldPool = pool.getAndSet(createScheduledThreadExecutor());
        oldPool.shutdownNow();
        claimedForHandoff.clear();
        workUnitsPeggedToMe.clear();
        state.set(NodeState.Fresh);
    }
1016185
def release_pool(self):
        """"""
        if self._current_acquired > 0:
            raise PoolException("Can't release pool: %d connection(s) still acquired" % self._current_acquired)
        while not self._pool.empty():
            conn = self.acquire()
            conn.close()
        if self._cleanup_thread is not None:
            self._thread_event.set()
            self._cleanup_thread.join()
        self._pool = None
795975
private synchronized void startWeakRefCleaner() {
        weakRefCleaner = new Thread(() -> {
            boolean running = true;
            while (running) {
                try {
                    // just wait, no need to get the - gc'ed object
                    weakReferenceQueue.remove();

                    // clean up the coordinateLines entries
                    final Set<String> coordinateLinesToRemove = new HashSet<>();
                    synchronized (coordinateLines) {
                        coordinateLines.forEach((k, v) -> {
                            if (null == v.get()) {
                                coordinateLinesToRemove.add(k);
                                if (logger.isTraceEnabled()) {
                                    logger.trace("need to cleanup gc'ed coordinate line {}", k);
                                }
                            }
                        });
                    }
                    // run on the JavaFX thread, as removeCoordinateLineWithId() calls methods from the WebView
                    Platform.runLater(() -> coordinateLinesToRemove.forEach(this::removeCoordinateLineWithId));

                    // clean up the MapCoordinateElement entries
                    final Set<String> mapCoordinateElementsToRemove = new HashSet<>();
                    synchronized (mapCoordinateElements) {
                        mapCoordinateElements.forEach((k, v) -> {
                            if (null == v.get()) {
                                mapCoordinateElementsToRemove.add(k);
                                if (logger.isTraceEnabled()) {
                                    logger.trace("need to cleanup gc'ed element {}", k);
                                }
                            }
                        });
                    }
                    // run on the JavaFX thread, as removeCoordinateLineWithId() calls methods from the WebView
                    Platform.runLater(
                            () -> mapCoordinateElementsToRemove.forEach(this::removeMapCoordinateElementWithId));
                } catch (InterruptedException e) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("thread interrupted");
                    }
                    running = false;
                }
            }
        });
        weakRefCleaner.setName("MapView-WeakRef-Cleaner");
        weakRefCleaner.setDaemon(true);
        weakRefCleaner.start();
    }
889684
private void cleanupConnection(Connection conn, ResultSet rs, PreparedStatement statement) {

		logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Entering",  new Object[] {conn, rs==null ? "<null>" : rs, statement==null ? "<null>" : statement});

		if (statement != null) {
			try {
				statement.close();
			} catch (SQLException e) {
				throw new PersistenceException(e);
			}
		}

		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				throw new PersistenceException(e);
			}
		}

		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				throw new PersistenceException(e);
			} finally {
				try {
					conn.close();
				} catch (SQLException e) {
					throw new PersistenceException(e);
				}
			}
		}
		logger.logp(Level.FINEST, CLASSNAME, "cleanupConnection", "Exiting");
	}
177812
def clean(self):
        ''''''
        if self.config.clean:
            logger.info('Cleaning')
            self.execute(self.config.clean)
801509
public synchronized void start()
	{
		pool.execute(this);

		while (state == RunState.CREATED)
		{
			sleep(null, null);
		}

		// Log the creation here so that it is deterministic...

		if (resource instanceof CPUResource)
		{
			CPUResource cpu = (CPUResource) resource;
			cpu.createThread(this);
		}
	}
878542
synchronized int cleanPools() {
        int totalConnectionsRemaining = 0;
        List<String> hostsToRemove = new ArrayList<String>();
        for (Map.Entry<String, TransportPool> hostPool : hostPools.entrySet()) {
            String host = hostPool.getKey();
            TransportPool pool = hostPool.getValue();

            int connectionsRemaining = pool.removeOldConnections();
            if (connectionsRemaining == 0) {
                hostsToRemove.add(host);
            } else {
                totalConnectionsRemaining += connectionsRemaining;
            }
        }

        // Remove old pools that now have no connections.
        for (String hostToRemove : hostsToRemove) {
            hostPools.remove(hostToRemove);
        }

        return totalConnectionsRemaining;
    }
273727
private synchronized void fillPool()
   {
      final int connectionsToAdd = Math.min(config.getMaximumPoolSize() - getTotalConnections(), config.getMinimumIdle() - getIdleConnections())
                                   - addConnectionQueue.size();
      for (int i = 0; i < connectionsToAdd; i++) {
         addConnectionExecutor.submit((i < connectionsToAdd - 1) ? poolEntryCreator : postFillPoolEntryCreator);
      }
   }