Fetching latest commit…
Cannot retrieve the latest commit at this time
|Failed to load latest commit information.|
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 @ https://github.com/jandre/powerpool. 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.