This has pool semantics, so consider making this a checkin/checkout style operation.
199382
public LuceneIndex current() {
    // Reopen index searcher if necessary.
    IndexSearcher oldSearcher = index.searcher.get();

    try {
      // Guarded lock, to prevent us from unnecessarily synchronizing every time.
      if (oldSearcher == null) {
        synchronized (this) {
          if ((oldSearcher = index.searcher.get()) == null) {
            IndexSearcher newSearcher = new IndexSearcher(index.directory);
            index.searcher.compareAndSet(null, newSearcher);
          }
        }

        // Yes it's open, but is it stale?
      } else {
        DirectoryReader directoryReader = DirectoryReader.openIfChanged(index.directory);
        if (null != directoryReader) {
          index.directory = directoryReader;

          synchronized (this) {
            IndexSearcher newSearcher;
            try {
              newSearcher = new IndexSearcher(directoryReader);
            } catch (AlreadyClosedException e) {
              log.warning("Old index reader could not be reopened. Opening a new one...");
              newSearcher = new IndexSearcher(DirectoryReader.open(index.writer, true));
            }
            if (!index.searcher.compareAndSet(oldSearcher, newSearcher)) {
              // Someone beat us to it. No worries.
              log.finest("Another searcher was already open for this index. Nothing to do.");
            }
          }
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    return index;
  }
491231
def create_checkout(self, **params):
        """"""
        for required in ['amount', 'currency', 'name']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'checkouts', data=params)
        return self._make_api_object(response, Checkout)
136146
def checkout(target, options = {})
      options[:strategy] ||= :safe
      options.delete(:paths)

      return checkout_head(options) if target == "HEAD"

      if target.kind_of?(Rugged::Branch)
        branch = target
      else
        branch = branches[target]
      end

      if branch
        self.checkout_tree(branch.target, options)

        if branch.remote?
          references.create("HEAD", branch.target_id, force: true)
        else
          references.create("HEAD", branch.canonical_name, force: true)
        end
      else
        commit = Commit.lookup(self, self.rev_parse_oid(target))
        references.create("HEAD", commit.oid, force: true)
        self.checkout_tree(commit, options)
      end
    end
492410
def checkin(result=nil)
      @reserved.delete ::Fiber.current.object_id
      @pool.unshift ::Fiber.current
      ::Fiber.yield
    end
830404
def checkout_code(repository, checkout_directory, branch)
      CodeCache.repo(repository).checkout(:head, checkout_directory, branch) or raise "Unable to checkout repository #{repository}"
    end
1189993
def insert_check(self, index, check_item):
        """"""
        self.checks.insert(index, check_item)
        for other in self.others:
            other.insert_check(index, check_item)
872647
def checkout(self, ref, branch=None):
        """"""
        return git_checkout(self.repo_dir, ref, branch=branch)
550850
private void requirePending() {
		if (pending != null) {
			return;
		}

		long exclusionComparable = Long.MIN_VALUE;
		while (nInclusionsRemaining != 0 && !queue.isEmpty()) {
			//find a candidate that is not excluded
			HeapElement inclusion = null;
			do {
				HeapElement candidate = queue.poll();
				if (candidate.inclusion) {
					if (exclusionComparable != candidate.comparable()) {
						inclusion = candidate;
						break;
					}
				} else {
					exclusionComparable = candidate.comparable();
				}
				reattach(candidate);
				if (nInclusionsRemaining == 0) {
					return;
				}
			} while (!queue.isEmpty());
			if (inclusion == null) {
				return;
			}
			long inclusionComparable = inclusion.comparable();

			/*
			 * Check for any following exclusions and for duplicates. We could
			 * change the sort order so that exclusions always preceded
			 * inclusions, but that would be less efficient and would make the
			 * ordering different than the comparable value.
			 */
			boolean excluded = exclusionComparable == inclusionComparable;
			while (!queue.isEmpty() && queue.peek().comparable() == inclusionComparable) {
				HeapElement match = queue.poll();
				excluded |= !match.inclusion;
				reattach(match);
				if (nInclusionsRemaining == 0) {
					return;
				}
			}
			if (!excluded) {
				pending = inclusion;
				return;
			}
			reattach(inclusion);
		}
	}
125829
def checkout(config, rev):
    """"""
    with open(config, 'r'):
        main.checkout(yaml.load(open(config)), rev)
390639
function execute(O $o) {
		if (df_is_checkout_multishipping()) {
			$p = $o['payment']; /** @var OP $p */
			/**
			 * 2017-08-28
			 * I intentionally do not use @see dfp_my() here, 
			 * because this function will instantiate a @see \Df\Payment\Method instance
			 * (or use a previously cached instance). 
			 */
			if (df_starts_with(($code = $p->getMethod()), 'dfe_')) { /** @var string $code */
				Method::sgReset();
				if ($cardId = Token::exchangedGet($code)) {  /** @var string|null $cardId */
					dfp_add_info($p, [Token::KEY => $cardId]);
				}
			}
		}
	}
481417
function (checks) {
			checks = checks || [];
			this.checks = [];
			for (var i = 0; i < checks.length; i = i + 1) {
				this.add(checks[i]);
			}
		}
933715
public void sanitize(){
		if (this.configFile != null){
			loadProperties(this.configFile);
		}

		if (this.poolStrategy == null || !(this.poolStrategy.equalsIgnoreCase("DEFAULT") || this.poolStrategy.equalsIgnoreCase("CACHED"))){
			logger.warn("Unrecognised pool strategy. Allowed values are DEFAULT and CACHED. Setting to DEFAULT.");
			this.poolStrategy = "DEFAULT";
		} 

		this.poolStrategy = this.poolStrategy.toUpperCase();

		if ((this.poolAvailabilityThreshold < 0) || (this.poolAvailabilityThreshold > 100)){
			this.poolAvailabilityThreshold = 20;
		}

		if (this.defaultTransactionIsolation != null){
			this.defaultTransactionIsolation = this.defaultTransactionIsolation.trim().toUpperCase();

			if (this.defaultTransactionIsolation.equals("NONE")){
				this.defaultTransactionIsolationValue = Connection.TRANSACTION_NONE;
			} else if (this.defaultTransactionIsolation.equals("READ_COMMITTED") || this.defaultTransactionIsolation.equals("READ COMMITTED")){
				this.defaultTransactionIsolationValue = Connection.TRANSACTION_READ_COMMITTED;
			} else if (this.defaultTransactionIsolation.equals("REPEATABLE_READ") || this.defaultTransactionIsolation.equals("REPEATABLE READ")){
				this.defaultTransactionIsolationValue = Connection.TRANSACTION_REPEATABLE_READ;
			} else if (this.defaultTransactionIsolation.equals("READ_UNCOMMITTED") || this.defaultTransactionIsolation.equals("READ UNCOMMITTED")){
				this.defaultTransactionIsolationValue = Connection.TRANSACTION_READ_UNCOMMITTED;
			} else if (this.defaultTransactionIsolation.equals("SERIALIZABLE")){
				this.defaultTransactionIsolationValue = Connection.TRANSACTION_SERIALIZABLE;
			} else {
				logger.warn("Unrecognized defaultTransactionIsolation value. Using driver default.");
				this.defaultTransactionIsolationValue = -1;
			}
		}
		if (this.maxConnectionsPerPartition < 1) {
			logger.warn("Max Connections < 1. Setting to 20");
			this.maxConnectionsPerPartition = 20;
		}
		if (this.minConnectionsPerPartition < 0) {
			logger.warn("Min Connections < 0. Setting to 1");
			this.minConnectionsPerPartition = 1;
		}

		if (this.minConnectionsPerPartition > this.maxConnectionsPerPartition) {
			logger.warn("Min Connections > max connections");
			this.minConnectionsPerPartition = this.maxConnectionsPerPartition;
		}
		if (this.acquireIncrement <= 0) {
			logger.warn("acquireIncrement <= 0. Setting to 1.");
			this.acquireIncrement = 1;
		}
		if (this.partitionCount < 1) {
			logger.warn("partitions < 1! Setting to 1");
			this.partitionCount = 1;
		}

		if (this.releaseHelperThreads < 0){
			logger.warn("releaseHelperThreads < 0! Setting to 0");
			this.releaseHelperThreads = 0;
		}

		if (this.statementReleaseHelperThreads < 0){
			logger.warn("statementReleaseHelperThreads < 0! Setting to 0");
			this.statementReleaseHelperThreads = 0;
		}

		if (this.statementsCacheSize < 0) {
			logger.warn("preparedStatementsCacheSize < 0! Setting to 0");
			this.statementsCacheSize = 0;
		}

		if (this.acquireRetryDelayInMs <= 0) {
			this.acquireRetryDelayInMs = 1000;
		}

		if (!this.externalAuth && 
				(this.datasourceBean == null) && 
				this.driverProperties == null 
				&& (this.jdbcUrl == null || this.jdbcUrl.trim().equals(""))){
			logger.warn("JDBC url was not set in config!");
		}

		if (!this.externalAuth && this.datasourceBean == null && this.driverProperties == null && 
				(this.username == null || this.username.trim().equals(""))){
			logger.warn("JDBC username was not set in config!");
		}

		if (!this.externalAuth && (this.datasourceBean == null) && (this.driverProperties == null) && (this.password == null)){ 
			logger.warn("JDBC password was not set in config!");
		}


		// if not external auth and no datasource and we have driver properties set...
		if (!this.externalAuth && this.datasourceBean == null && this.driverProperties != null){
			if ((this.driverProperties.get(USER) == null) && this.username == null){
				logger.warn("JDBC username not set in driver properties and not set in pool config either");
			} else if ((this.driverProperties.get(USER) == null) && this.username != null){
				logger.warn("JDBC username not set in driver properties, copying it from pool config");
				this.driverProperties.setProperty(USER, this.username);
			} else if (this.username != null && !this.driverProperties.get(USER).equals(this.username)){
				logger.warn("JDBC username set in driver properties does not match the one set in the pool config.  Overriding it with pool config.");
				this.driverProperties.setProperty(USER, this.username);
			}  
		}

		// if no datasource and we have driver properties set...
		if (!this.externalAuth && this.datasourceBean == null && this.driverProperties != null){
			if ((this.driverProperties.get(PASSWORD) == null) && this.password == null){
				logger.warn("JDBC password not set in driver properties and not set in pool config either");
			} else if ((this.driverProperties.get(PASSWORD) == null) && this.password != null){
				logger.warn("JDBC password not set in driver properties, copying it from pool config");
				this.driverProperties.setProperty(PASSWORD, this.password);
			} else if (this.password != null && !this.driverProperties.get(PASSWORD).equals(this.password)){
				logger.warn("JDBC password set in driver properties does not match the one set in the pool config. Overriding it with pool config.");
				this.driverProperties.setProperty(PASSWORD, this.password);
			}



			// maintain sanity between the two states 
			this.username = this.driverProperties.getProperty(USER);
			this.password = this.driverProperties.getProperty(PASSWORD);
		}

		if (this.username != null){
			this.username = this.username.trim();
		}
		if (this.jdbcUrl != null){
			this.jdbcUrl = this.jdbcUrl.trim();
		}
		if (this.password != null){
			this.password = this.password.trim();
		}

		if (this.connectionTestStatement != null) { 
			this.connectionTestStatement = this.connectionTestStatement.trim();
		}

		this.serviceOrder = this.serviceOrder.toUpperCase();

		if (!(this.serviceOrder.equals("FIFO") || this.serviceOrder.equals("LIFO"))){
			logger.warn("Queue service order is not set to FIFO or LIFO. Defaulting to FIFO.");
			this.serviceOrder = "FIFO";
		}
		
		if (this.logStatementsEnabled && !logger.isDebugEnabled()){
			logger.warn("LogStatementsEnabled is set to true, but log4j level is not set at DEBUG. Disabling statement logging.");
			logStatementsEnabled = false;
			
		}

	}
482322
@Override
    public void checkin(K key, V resource) {
        super.checkin(key, resource);
        // NB: Blocking checkout calls for synchronous requests get the resource
        // checked in above before processQueueLoop() attempts checkout below.
        // There is therefore a risk that asynchronous requests will be starved.
        processQueueLoop(key);
    }
77348
def sweep(crypto, private_key, to_address, fee=None, password=None, **modes):
    
    from moneywagon.tx import Transaction
    tx = Transaction(crypto, verbose=modes.get('verbose', False))
    tx.add_inputs(private_key=private_key, password=password, **modes)
    tx.change_address = to_address
    tx.fee(fee)

    return tx.push()
595701
def checkout(self, ref, cb=None):
        """"""
        if self.is_api:
            return self._checkout_api(ref, cb=cb)
        else:
            return self._checkout_fs(ref, cb=cb)
1007369
protected void maybeSignalForMoreConnections(ThriftConnectionPartition<T> connectionPartition) {
		if (!connectionPartition.isUnableToCreateMoreTransactions() && !this.poolShuttingDown
				&& connectionPartition.getAvailableConnections() * 100
						/ connectionPartition.getMaxConnections() <= this.poolAvailabilityThreshold) {
			connectionPartition.getPoolWatchThreadSignalQueue().offer(new Object());
		}
	}
583134
def _checkout(self, treeish):
        '''
        
        '''

        return self.m(
            'checking out "%s"' % (treeish),
            cmdd=dict(cmd='git checkout %s' % (treeish), cwd=self.local),
            verbose=False
        )