【发布时间】:2012-04-02 11:49:00
【问题描述】:
我们计划在我们的 java 应用程序中实现连接池。我们用谷歌搜索了很多,例如 BoneCp、DbPool、Apache、c3p0、DbCp 等。我们现在发现的问题是很难决定应用哪一个,因为有些已经过时了。哪种方法是最好的解决方案?
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 池吗?这限制了很多选项。
-
@clement XA 池化是什么意思?所以我放了我的部分代码。您建议哪种方式?