Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Latest commit

 

History

History
35 lines (29 loc) · 1.15 KB

README.md

File metadata and controls

35 lines (29 loc) · 1.15 KB

Multiway Object Pool

A concurrent object pool that supports pooling multiple resources that are associated with a single key. This is a proof-of-concept implementation for @jbellis with regards to CASSANDRA-5661.

Usage

A pool might manage the connections for databases, such as a master and multiple slaves.

LoadingMultiwayPool<String, Connection> pool = MultiwayPoolBuilder.newBuilder()
    .maximumSize(50)
    .expireAfterAccess(10, TimeUnit.MINUTES)
    .lifecycle(new ResourceLifecycle<String, Connection>() {
      public void onRemoval(String key, Connection connection) {
        connection.close();
      }
    })
    .build(new ResourceLoader<String, Connection>() {
      public Connection load(String databaseName) {
        // create connection to database
      }
    });

Connection connection = pool.borrow("master");
try {
  // use connection...
} finally {
  pool.release(connection);
}

Optimized using JProfiler, a full-featured Java profiler licensed freely to open source projects.