[英]Java connection pooling options
我们计划将连接池实现到我们的Java应用程序中。 我们在Google上找到了很多,例如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);
}
}
}
首先,从连接池中确定您需要的内容,然后查找提供该功能的库。
使用网络上已有的流行观点或在SO上提出具体问题,现在选择一种。
接下来,再次根据池中的需求,为连接池功能创建一个抽象层,并使用选定的库进行实现。
这样,即使您在开发过程中不满意,也可以更改基础库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.