BONECP is a fast, free, Open-source, Java database connection pool (JDBC pool) library. If you are are familiar with C3P0 and DBCP then your already know what this means. For the rest, this is a library of that would manage a database connection for you to get faster database access in your appli cation.
BONECP is fast! For some tests, it's almost faster than the next fastest connection pool option, not to mention that BONECP never Spin-locks so it won ' t slow down your application.
Official home: http://jolbox.com/
Download Address: http://jolbox.com/bonecp/downloads/maven/com/jolbox/bonecp/
The latest version is: 0.6.7.2
Dependent jar Pack: A database that accepts connections a driver to go with it Google Guava library, available fo R free From here. The slf4j logging Library. JDK1.5 or higher.
That
Bonecp-0.7.0.jar
Google-collections-1.0.jar
Log4j-1.2.15.jar
Mysql-connector-java-5.1.6-bin.jar (MySQL-driven)
Slf4j-api-1.5.10.jar
Slf4j-log4j12-1.5.10.jar
The above Jar pack can be downloaded here http://jolbox.com/bonecp/downloads/maven/
Dot I download this article engineering code
Using the BONECP connection pool in JDBC
Package COM.BONECP;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
Import Com.jolbox.bonecp.BoneCP;
Import Com.jolbox.bonecp.BoneCPConfig;
/**
* @author sxyx2008
*
*/
public class Examplejdbc {
public static void Main (string[] args) {
BONECP connectionpool = null;
Connection Connection = null;
try {
Load the database driver (make sure-your classpath!)
Class.forName ("Com.mysql.jdbc.Driver");
catch (Exception e) {
E.printstacktrace ();
return;
}
try {
Setup the connection pool
Bonecpconfig config = new Bonecpconfig ();
Config.setjdbcurl ("Jdbc:mysql://localhost:3306/demo"); JDBC URL specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
Config.setusername ("root");
Config.setpassword ("root");
Set the number of free connections in the database to be checked every 60 seconds
Config.setidleconnectiontestperiod (60);
Set Connection idle time
Config.setidlemaxage (240);
Set the maximum number of connections in each partition 30
Config.setmaxconnectionsperpartition (30);
Set the minimum number of connections in each partition 10
Config.setminconnectionsperpartition (10);
Number of simultaneous BONECP connections when the connection in the connection pool is depleted
Config.setacquireincrement (5);
Connection Release Processing
Config.setreleasehelperthreads (3);
Set partition number to 3
Config.setpartitioncount (3);
Setting Configuration parameters
ConnectionPool = new BONECP (config); Setup the connection pool
Connection = Connectionpool.getconnection (); Fetch a connection
if (connection!= null) {
System.out.println ("Connection successful!");
Statement stmt = Connection.createstatement ();
ResultSet rs = stmt.executequery ("SELECT * from person"); Do something with the connection.
while (Rs.next ()) {
System.out.println (rs.getstring (1)); Should print out "1"
System.out.println (rs.getstring (2)); Should print out "1"
}
}
Connectionpool.shutdown (); Shutdown connection pool.
catch (SQLException e) {
E.printstacktrace ();
finally {
if (connection!= null) {
try {
Connection.close ();
catch (SQLException e) {
E.printstacktrace ();
}
}
}
}
}
Use DataSource package COM.BONECP;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
Import Com.jolbox.bonecp.BoneCPDataSource;
public class Exampledatasource {
public static void Main (string[] args) {
Connection Connection = null;
try {
Class.forName ("Com.mysql.jdbc.Driver");
catch (Exception e) {
E.printstacktrace ();
}
Bonecpdatasource DataSource = new Bonecpdatasource ();
Datasource.setusername ("root");
Datasource.setpassword ("root");
Datasource.setjdbcurl ("Jdbc:mysql://localhost:3306/demo");
Datasource.setmaxconnectionsperpartition (10);
Datasource.setminconnectionsperpartition (5);
Datasource.setidleconnectiontestperiod (60);
Datasource.setidlemaxage (240);
Datasource.setacquireincrement (5);
Datasource.setreleasehelperthreads (3);
try {
Connection = Datasource.getconnection ();
if (Connection!=