Example usage for org.apache.commons.pool2.impl PooledSoftReference PooledSoftReference

List of usage examples for org.apache.commons.pool2.impl PooledSoftReference PooledSoftReference

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl PooledSoftReference PooledSoftReference.

Prototype

public PooledSoftReference(SoftReference<T> reference) 

Source Link

Document

Creates a new PooledSoftReference wrapping the provided reference.

Usage

From source file:com.skynetcomputing.database.Database.java

/**
 * Creates a new database connection pool so that statements and queries can be executed.
 *///from  w  w  w  .j  a  v  a 2s . co m
@SuppressWarnings("unchecked")
private Database() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxIdle(5);
    config.setMaxTotal(10);

    // Configurable connectionstring.
    String connString = MiscUtils.getPropertyOrDefault("dbConnection", URL);
    String connUser = MiscUtils.getPropertyOrDefault("dbUser", USERNAME);
    String connPassword = MiscUtils.getPropertyOrDefault("dbPassword", PASSWORD);

    pool = new GenericObjectPool<>(new BasePooledObjectFactory() {
        @Override
        public Object create() throws Exception {
            return DriverManager.getConnection(connString, connUser, connPassword);
        }

        @Override
        public PooledObject wrap(Object o) {
            return new PooledSoftReference<>(new SoftReference<>(o));
        }
    }, config);
}