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

ben-manes/multiway-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Multiway object pool (experiment)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published