View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

Modules:Apache JDBC Connection Pool

Bulbgraph.png   The use of external connection pools is available from 3.0PR14Q2
Bulbgraph.png   This module was sponsored through Agility ERP, and is applicable for managing Openbravo workloads that may generate a large number of concurrent queries to the database.

Contents

Introduction

Openbravo uses connection pools to reuse existing connections/prepared statements, avoiding the cost of initiating a connection, parsing SQL etc. By default Openbravo uses two different connection pools:

From 3.0PR14Q2 it is possible to specify an external connection provider to replace these two connection pools. Openbravo provides a free commercial module that implements the Tomcat JDBC Connection Pool.

Bulbgraph.png   Apache JDBC Connection Pool module is included within Openbravo 3.0 distribution as free starting from 3.0PR15Q4

Advantages of using JDBC Connection Pool

Inclusion in Openbravo.properties

Openbravo will not start using the external connection pool until the module has been installed and the following line has been added to Openbravo.properties:

db.externalPoolClassName=org.openbravo.apachejdbcconnectionpool.JdbcExternalConnectionPool

Pool Configuration

The following default properties configure the behaviour of the pool:

........
 
######################
# DB connection pool #
######################
 
db.externalPoolClassName=org.openbravo.apachejdbcconnectionpool.JdbcExternalConnectionPool
 
# Documentation at http://wiki.openbravo.com/wiki/Modules:Apache_JDBC_Connection_Pool#Pool_Configuration
db.pool.initialSize=1
db.pool.minIdle=5
db.pool.maxActive=10000
db.pool.timeBetweenEvictionRunsMillis=60000
db.pool.minEvictableIdleTimeMillis=120000
db.pool.removeAbandoned=false
db.pool.testOnBorrow=true
db.pool.testWhileIdle=false
db.pool.testOnReturn=false
db.pool.validationQuery=SELECT 1 FROM DUAL
db.pool.validationInterval=30000
 
........


The Apache JDBC Connection Pool can be configured to meet your environment needs. These are the different configured properties in Openbravo.properties:

The full list of configurable properties can be found here. This link provides information about about how to configure these properties for high concurrent environments.

How does the Sweeper thread work?

It has already been explained than the sweeper runs every db.pool.timeBetweenEvictionRunsMillis milliseconds. This sweeper can be enabled or disabled:

The sweeper is enabled when one of the following conditions is met:

Bulbgraph.png   By default, the sweeper is enabled because the behavior of the pool provides a better adjustment to the conditions of each environment.

Adding Interceptors

Adding a custom interceptor is very easy. You just need to take the following in consideration:

package org.openbravo.tomcatjdbcconnectionpool;
 
import java.lang.reflect.Method;
 
import javax.enterprise.context.ApplicationScoped;
 
import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
import org.apache.tomcat.jdbc.pool.PooledConnection;
import org.openbravo.database.PoolInterceptorProvider;
 
@ApplicationScoped
public class TestInterceptor extends JdbcInterceptor implements PoolInterceptorProvider {
 
  public void reset(ConnectionPool parent, PooledConnection con) {
    // Actions after a connection has been borrowed from the pool
  }
 
  // Gets invoked each time an operation on Connection is invoked.
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // Actions before the method invocation
    Object object = super.invoke(proxy, method, args);
    // Actions before the method invocation
    return object;
  }
 
  @Override
  // Return the full name of the interceptor class
  public String getPoolInterceptorsClassName() {
    String fullClassName = this.getClass().getName();
    return fullClassName + ";";
  }
}

Retrieved from "http://wiki.openbravo.com/wiki/Modules:Apache_JDBC_Connection_Pool"

This page has been accessed 3,411 times. This page was last modified on 7 August 2015, at 08:26. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.