Project

General

Profile

« Previous | Next » 

Revision 1219

Added by Jing Tao almost 22 years ago

Add a new method to shrink DBConnection pool size.

View differences:

src/edu/ucsb/nceas/metacat/DBConnectionPool.java
569 569
  /**
570 570
   * Method to get the number of free DBConnection in DBConnection pool
571 571
   */
572
  public int getFreeDBConnectionNumber()
572
  public static synchronized int getFreeDBConnectionNumber()
573 573
  {
574 574
    int numberOfFreeDBConnetion = 0; //return number
575 575
    DBConnection db = null; //single DBconnection
......
618 618
  
619 619
  }//printMethodNameHavingBusyDBConnection
620 620
  
621
  /**
622
   * Method to decrease dbconnection pool size when all dbconnections are idle
623
   * If all connections are free and connection pool size greater than 
624
   * initial value, shrink connection pool size to intital value
625
   */
626
  public static synchronized void shrinkDBConnectionPoolSize()
627
  {
628
     int connectionPoolSize = 0; //store the number of dbconnection pool size
629
     int freeConnectionSize = 0; //store the number of free dbconnection in pool
630
     int difference = 0; // store the difference number between connection size
631
                         // and free connection
632
     DBConnection conn = null;
633
     connectionPoolSize = connectionPool.size();
634
     freeConnectionSize = getFreeDBConnectionNumber();
635
     MetaCatUtil.debugMessage("Connection pool size: " +connectionPoolSize, 20);
636
     MetaCatUtil.debugMessage("Free Connection number: "+freeConnectionSize,20);
637
     difference = connectionPoolSize - freeConnectionSize;
638
     
639
     //If all connections are free and connection pool size greater than 
640
     //initial value, shrink connection pool size to intital value
641
     if (difference == 0 && connectionPoolSize > INITIALCONNECTIONNUMBER)
642
     {
643
       //db connection having index from intialConnectionnumber - 1 to
644
       //connectionpoolsize -1 should be close and remove from pool
645
       for ( int i=INITIALCONNECTIONNUMBER -1; i<connectionPoolSize; i++)
646
       {
647
         //get the dbconnection from pool
648
         conn = (DBConnection) connectionPool.elementAt(i);
649
         //close conn
650
         
651
         try
652
         {
653
           conn.close();
654
         }//try
655
         catch (SQLException e)
656
         {
657
           MetaCatUtil.debugMessage("Couldn't close the DBConnection in" +
658
                         " DBConnectionPool.shrinkDBConnectionPoolSize: " +
659
                         e.getMessage(), 30);
660
         }//catch
661
         //remove it from pool
662
         connectionPool.remove(i);
663
       }//for
664
     }//if
665
  }//shrinkDBConnectionPoolSize
666
     
667
   
668
  
621 669
}//DBConnectionPool

Also available in: Unified diff