We plan to implement connection pooling as that appears to be the right mechanism to use when database connections are frequently opening and closing. We display our code below, but need to know where must we do the connection pooling definition. Should it be in the main()
method itself or in the ConnectionHandler
class? Another thing: what are the opinions regarding BoneCP?
public class cServer
{
class ConnectionHandler implements Runnable {
ConnectionHandler(Socket receivedSocketConn1) {
this.receivedSocketConn1=receivedSocketConn1;
}
public void run(){
createConnection();
processData();
closeConnection();
}
}
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);
}
}
}