class PoolWatchThread implements Runnable {

	public void run() {
		int maxNewConnections;
		while (!this.signalled){
			maxNewConnections=0;

			try{
				if (this.lazyInit){ // block the first time if this is on.
					this.partition.getPoolWatchThreadSignalQueue().take();
				}
 

				maxNewConnections = this.partition.getMaxConnections()-this.partition.getCreatedConnections();
				// loop for spurious interrupt
				while (maxNewConnections == 0 || (this.partition.getAvailableConnections() *100/this.partition.getMaxConnections() > this.poolAvailabilityThreshold)){
					if (maxNewConnections == 0){
						this.partition.setUnableToCreateMoreTransactions(true);
					}
					
					this.partition.getPoolWatchThreadSignalQueue().take();
					maxNewConnections = this.partition.getMaxConnections()-this.partition.getCreatedConnections();
					
				}

				if (maxNewConnections > 0 
						&& !this.pool.poolShuttingDown){
					fillConnections(Math.min(maxNewConnections, this.partition.getAcquireIncrement()));
					// for the case where we have killed off all our connections due to network/db error
					if (this.partition.getCreatedConnections() < this.partition.getMinConnections()){
						fillConnections(this.partition.getMinConnections() - this.partition.getCreatedConnections() );
							
					}
				}
				
				if (this.pool.poolShuttingDown){
					return;
				}


			} catch (InterruptedException e) {
				logger.debug("Terminating pool watch thread");
				return; // we've been asked to terminate.
			}
		}
	}

	public  PoolWatchThread(ConnectionPartition connectionPartition, BoneCP pool);

}