/*
 * PoolManager.java
 *
 * Created on 2 de agosto de 2004, 14:35
 */

package com.fenalco.utilities.database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author  Andrés Romero Rodríguez
 *
 * Esta clase se encarga de mantener el pool eliminando las conexiones que 
 * no se estén utilizando
 */
public class PoolManager extends Thread
{
    private DataBaseConnection dbc;
    
    /** Creates a new instance of PoolManager */
    public PoolManager( DataBaseConnection c )
    {
        super();
        dbc = c;
    }
    
    public void run()
    {
        while( true )
        {
            try
            {
                sleep( dbc.getTimeOut() * 1000 );
            }
            catch( InterruptedException e )
            {
                
            }
            
            Vector freeConn = dbc.getFreeConnections();
            if( freeConn.size() > 0 )
            {
                Connection c = ( Connection )freeConn.remove( 0 );
                try
				{
					c.close( );
				}
				catch( SQLException e1 )
				{
					e1.printStackTrace();
				}
            }
        }
    }
    
}
