我們計劃在我們的java應用程序中實現連接池。我們谷歌和發現了它的一些如BoneCp,DbPool,Apache,c3p0,DbCp和其他。現在我們發現問題很難做出決定,哪一個適用,有些已經過時。哪種方法是最佳解決方案?Java連接池選項
public class cServer
{
class ConnectionHandler implements Runnable {
ConnectionHandler(Socket receivedSocketConn1) {
this.receivedSocketConn1=receivedSocketConn1;
}
public void run(){
createConnection();
while (read the socket values){
//number of queries to run in terms of select,insert and updates.
}
closeConnection();
}
void createConnection(){
try{
dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1?"+"user=user1&password=*******");
dbconn.setAutoCommit(false);
}
catch(Throwable ex){
ex.printStackTrace(System.out);
}
}
}
public void main()
{
try
{
final ServerSocket serverSocketConn = new ServerSocket(8000);
while (true){
try{
Socket socketConn1 = serverSocketConn.accept();
new Thread(new ConnectionHandler(socketConn1)).start();
}
catch(Exception e){
e.printStackTrace(System.out);
}
}
}
catch (Exception e){
e.printStackTrace(System.out);
}
}
}
你需要XA池嗎?這限制了相當多的選擇。 – 2012-03-16 23:21:48
2011年Java JDBC連接池庫選擇可能的重複?(http://stackoverflow.com/questions/5640146/java-jdbc-connection-pool-library-choice-in-2011) – 2012-03-16 23:22:09
@clement你是什麼是由XA池?所以我已經把我的部分代碼。你建議哪種方式? – user837306 2012-03-18 14:27:14