Hello,
I copied this class from this site somewhere and its working great. But I'm having issue of 'connection reset' and 'Broken Pipe' error messages. Since I'm not the owner of this class I dont know where to make modification in order to close the connection or delete or make it expired, that was told by someone to me in order to get rid of that error msg.
1 Can anyone tell me basic idea what this below class do, just for my total understanding?
2. Can we close or delete or expire connection in this class ? If not, why not ? Whatz other alternative ?
Thanks for you time.
I copied this class from this site somewhere and its working great. But I'm having issue of 'connection reset' and 'Broken Pipe' error messages. Since I'm not the owner of this class I dont know where to make modification in order to close the connection or delete or make it expired, that was told by someone to me in order to get rid of that error msg.
1 Can anyone tell me basic idea what this below class do, just for my total understanding?
2. Can we close or delete or expire connection in this class ? If not, why not ? Whatz other alternative ?
Code:
public class Pool
{
private static Pool p=null;
private Vector con_pool=null;
private Vector used_connections=null;
private Connection c=null;
private int cache_size=10;
public static Pool getInstance()
{
if (p==null)
p=new Pool();
return p;
}
public Pool()
{
con_pool=new Vector();
used_connections=new Vector();
for(int i=0;i<cache_size;i++)
{
c=create();
con_pool.addElement(c);
}
}
public Connection get_Connection()
{
Connection temp=null;
if (con_pool.size()>0)
{
temp=(Connection) con_pool.firstElement();
used_connections.addElement(temp);
con_pool.removeElement(con_pool.firstElement());
}
else
{
temp=create();
used_connections.addElement(temp);
}
return temp;
}
public void return_Connection(Connection con)
{
Enumeration enum=used_connections.elements();
Connection temp=null;
while(enum.hasMoreElements())
{
temp=(Connection) enum.nextElement();
if (temp==con)
{
used_connections.removeElement(temp);
con_pool.addElement(temp);
break;
}
}
}
public Connection create()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
c= DriverManager.getConnection("....");
}
catch(Exception e)
{
System.out.println("Error in create..");
}
return c;
}
}