Apache Commons Configuration: Keep database connection open

203 views Asked by At

We use Apache Commons Configuration 1.8 with Java 7. One of the data sources is a PostgreSQL database, accessed via DatabaseConfiguration in a class which acts as a singleton.

Demo configuration initialization:

private void init()
{
  // ...
  this.databaseConfiguration =
           new DatabaseConfiguration( getDataSource(),
                 "configuration",
                 "key",
                 "value" );
  this.config.addConfiguration( this.databaseConfiguration, true );
  // ...
}

private DataSource getDataSource()
{
  final Jdbc3SimpleDataSource source = new Jdbc3SimpleDataSource();
  source.setServerName( "my_server" );
  source.setPortNumber( 5432 );
  source.setDatabaseName( "database" );
  source.setUser( "user" );
  source.setPassword( "password" );
  return source;
}

We noticed that we have up to 80 database connections per second. They are short lived (around 20ms) and often read only a single configuration value from the database before they are closed.

Is there a way to configure Apache Commons Configuration to keep the database connection open?

0

There are 0 answers