Abstract
| Goal |
Configure JDBC database drivers and data sources. |
| Objectives |
|
| Sections |
|
| Lab |
|
Most Jakarta Enterprise Edition (Jakarta EE) applications involve a database that contains the information that the users need to access and perform the basic create, read, update, and delete (CRUD) operations. A data source is an application server feature that provides database access to an application without exposing sensitive information, such as credentials and database location. To connect to a database, the application uses a name bound to the data source via the application server. For a Jakarta EE application server, the name is defined by the Java Naming and Directory Interface (JNDI) specification.
By using a Java Database Connectivity (JDBC) API specific to a relational database management system, users can fine tune a data source to maximize efficiency and manage load on the database.
Data sources are configured through the Datasource Subsystem. Declaring a new data source consists of two separate steps:
Installing the JDBC driver for a particular database server vendor.
Define a data source within the datasource subsystem of the configuration file.
See the JBoss EAP supported configurations reference for a list of database vendors that JBoss EAP supports.
You specify which type of datasource to use when creating the datasource using the JBoss EAP management interface. The two general types of resources are referred to as datasources and XA datasources.
Used for applications that use transactions with a single database.
Used by applications that use multiple databases or other XA resources as part of one XA transaction.
One obstacle to overcome when managing a data source is being able to handle traffic and concurrent connections to the database. It can be a potential bottleneck and a performance concern during peak loads for the deployed applications.
To improve data access performance, JBoss EAP creates a database connection pool to provide the application with ready-to-use database connections. Having pre-established connections avoids the overhead of opening and closing a connection for every single request. The size of the connection pool can be configured for each data source.
Each database instance used by an application requires its own connection pool.
JBoss EAP 7 detects database connections issues by using one of the following the validation methods:
This specifies a connection checker class that validates connections.
JBoss EAP provides validation checker classes in the org.jboss.jca.adapters.jdbc.extensions package.
This is the preferred method.
By using this method you provide the SQL statement that runs to validate the connection.
You can configure when to execute the validations by using one of the following options:
This method validates database connections when they are pulled from the connection pool. This method results in the quickest connection recovery, but it also creates more load on the database. If the connection is found to be invalid, the next connection from the pool is used and a warning is logged. The server continues to cycle through the connection pool looking for a valid connection. If no connection in the pool is valid, a new one is created. If creating the connection fails, an exception is returned.
This method validates database connections periodically.
The background-validation-millis property value specifies the validation frequency.
By setting the validation time to a lower value, the connection is validated more often, but it also requires more resources and a greater load on the database.
When a connection throws a fatal exception, then the connection is closed immediately. You can use one of the exception sorters that JBoss EAP provides to detect the exception and do the clean up.
To avoid database connection leaks, configure the cached connection manager to debug.
This closes the leaked connections and prints INFO log messages to inform about the issue.
To avoid connection leaks, it is recommended to code with the try-with-resources Java construct.
See the references for further information about database connection leaks.
To learn deeper details about data sources fault tolerance, see EAP 6/7 JDBC datasource not fault tolerant in JBoss and needs connection validation enabled reference.
JBoss EAP supported configurations
Detecting leaked datasource connections using the cached connection manager (CCM) in JBoss EAP
How to solve the Unable to get managed connection error
To learn more about the fault tolerance of data sources, see the EAP 6/7 JDBC datasource not fault tolerant in JBoss and needs connection validation enabled knowledge base article at https://access.redhat.com/solutions/156103
For more information, refer to the Database Connection Validation section in the Datasource Management chapter in the Red Hat Red Hat JBoss Enterprise Application Platform 7.4 Configuration Guide documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuration_guide/index#configure_database_connection_validation_settings