All Packages Class Hierarchy This Package Previous Next Index
Class com.studioitech.gulli.MJDBC.dbArbiterConnections
java.lang.Object
|
+----com.studioitech.gulli.MJDBC.dbArbiterConnections
- public class dbArbiterConnections
- extends Object
A Connection represents a session with a specific
database. Within the context of a Connection, SQL statements are
executed and results are returned.
This package allows user to init a lot of JDBC Connections to
a database. These connections are never closed until the end of
the user program and they are handled in mutex way: i mean, they
are multi-thread safe.
An example of benefit of this, is servlet programming. In
servlet model you have an init phase (during which servlet is
allocated) a destroy phase (during which servlet is deallocated)
and a doGet (or similiar ...). The init and destroy method are
called by the HTTP server in single-thread enviroment. The doGet
method works in a multi-thread enviroment.
The HTTP server for every incoming GET request directed to
servlet create a new thread and execute the doGet code.
By using this package, you can open a lot of connection to
the DB during the init phase. Use them in multi-thread safe mode
during the doGet call. Only close them when the servlet is discarded
from HTTP server.
Benefits are in term of performance. In fact, using traditional
cgi-bin like paradigm, for every incoming request you have this
cycle:
- Open DB
- Perform SQL Query and get Results
- Close DB
Opening and Close a DB is a very costly operation. This is true in
direct access to a given database via a propreatary API, This become
most evident if you access the database via the JDBC layer because you
have to count the time to load the JDBC driver. So is better to perform
these costly operation at the init time once.
Using this package you can move to a new paradigm, for every incoming
request you have this cycle:
- Get an available connection to the DB and mark it as used
- Perform SQL Query and get Results
- Mark used connection as available
For a large volume of requests avoiding to load JDBC driver, open and
close continuosly means to have a less latency in answering.
-
dbArbiterConnections(String, String, String, String, int)
- Constructor of the ArbiterConnections: It opens ncons dbConnection
and init their multi-thread safe handling
-
getAnAvailableCon()
- Get an available connection in the opened pool of dbConnection
-
getNumAllocatedCon()
- Get the number of connection in the pool of opened dbConnection
-
shutdown()
- Close all available dbConnection
dbArbiterConnections
public dbArbiterConnections(String JDBC_DriverName,
String url,
String usr,
String pwd,
int ncons) throws SQLException, ClassNotFoundException
- Constructor of the ArbiterConnections: It opens ncons dbConnection
and init their multi-thread safe handling
- Parameters:
- JDBC_DriverName - the name of JDBC driver
- url - the url to connect database (e.g.: jdbc:postgresql:database )
- usr - the name of database's user (e.g.: test)
- pwd - the password database user (e.g.: test)
- ncons - number of connection to open
- Throws: SQLException
- if a database-access error occurs.
- Throws: ClassNotFoundException
- if the JDBC driver is not
available
getAnAvailableCon
public dbConnection getAnAvailableCon()
- Get an available connection in the opened pool of dbConnection
- Returns:
- dbConnection, the chosen available connection
- See Also:
- dbConnection
shutdown
public void shutdown() throws SQLException
- Close all available dbConnection
- Throws: SQLException
- if a database-access error occurs
getNumAllocatedCon
public int getNumAllocatedCon()
- Get the number of connection in the pool of opened dbConnection
- Returns:
- dbConnection the number of available connections
- See Also:
- dbConnection
All Packages Class Hierarchy This Package Previous Next Index