Package edu.ucsb.nceas.metacat.database
Class DBConnectionPool
java.lang.Object
edu.ucsb.nceas.metacat.database.DBConnectionPool
- All Implemented Interfaces:
Runnable
A class represent a DBConnection pool. Another user can use the
object to initial a connection pool, get db connection or return it.
This a singleton class, this means only one instance of this class could
be in the program at one time.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DBConnection
getDBConnection
(String methodName) Method to get a DBConnection in connection pool 1) try to get a DBConnection from DBConnection pool 2) if 1) failed, then check the size of pool.static DBConnectionPool
Returns the single instance, creating one if it's the first time this method is called.int
Method to get the size of DBConnectionPoolstatic void
release()
Method to shut down all connectionsstatic void
returnDBConnection
(DBConnection conn, int serialNumber) Method to return a connection to DBConnection pool.void
run()
periodically to recycle the connectionstatic boolean
Method to decrease dbconnection pool size when all dbconnections are idle If all connections are free and connection pool size greater than initial value, shrink connection pool size to initial valuestatic void
Method to decrease dbconnection pool size when all dbconnections are idle If all connections are free and connection pool size greater than initial value, shrink connection pool size to intital value
-
Method Details
-
getInstance
Returns the single instance, creating one if it's the first time this method is called.- Throws:
SQLException
-
getSizeOfDBConnectionPool
public int getSizeOfDBConnectionPool()Method to get the size of DBConnectionPool -
getDBConnection
Method to get a DBConnection in connection pool 1) try to get a DBConnection from DBConnection pool 2) if 1) failed, then check the size of pool. If the size reach the maximum number of connection, throw a exception: couldn't get one 3) If the size is less than the maximum number of connectio, create some new connections and recursive get one- Parameters:
methodName
- , the name of method which will check connection out- Throws:
SQLException
-
returnDBConnection
Method to return a connection to DBConnection pool.- Parameters:
conn
- , the Connection object need to check in
-
release
public static void release()Method to shut down all connections -
run
public void run()periodically to recycle the connection -
shrinkConnectionPoolSize
public static boolean shrinkConnectionPoolSize()Method to decrease dbconnection pool size when all dbconnections are idle If all connections are free and connection pool size greater than initial value, shrink connection pool size to initial value -
shrinkDBConnectionPoolSize
public static void shrinkDBConnectionPoolSize()Method to decrease dbconnection pool size when all dbconnections are idle If all connections are free and connection pool size greater than initial value, shrink connection pool size to intital value
-