Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (22 sloc) 1.49 KB
Hello, this is a sample database connection pooling class I created for an interview.
Naturally, in writing it, I sort of got carried away. :(
Perhaps it will be a useful example to someone else.
Latest version is at @
to build powerpool.jar:
- ant dist
to run tests (some tests use hsqldb):
- ant test
to create a connection pool:
SimpleConnectionPool pool = SimpleConnectionPool.createDefaultPool("org.hsqldb.jdbc.JDBCDriver",
"jdbc:hsqldb:mem:power-test", "sa", "password");
Connection connection = pool.getConnection();
// TODO: do some stuff with the connection...
pool.releaseConnection(connection); // or, you can call connection.close();
pool.stop(); // release any idle resources;.
Configuration options are controlled by the "Settings" class. Basically, there's two things you can configure:
1) MaximumIdleTimeSeconds: the maximum time a free connection can idle before it is closed so the resources can be reclaimed.
- the maximum time a free connection can idle before it is closed.
- default = 60 * 5 seconds (5 minutes). -1 = let all threads idle forever (not recommended unless you set a max limit.
2) MaximumConnections: maximum number of connections that can be assigned. The pool will not block if the queue is full, it will throw an exception.
- default = unlimited connections.
- if you set this to <= 0, it resets it to unlimited.