Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 why the jdbc connection pool always try to create a new connection to the DB server?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-05-03 : 10:28:53
jacky writes "I use connection pool from the ms's jdbc driver.

But i found every time i want to use the connection, the programm always create a new connetion, instead of fetch the connection from the pool. There are many query need to do, so it used up the resource of db server and the client. Even i set the pool size is 2500, it can't work out!

what's the problem of it?Thx a lot!

//start of the code

package kwe.util ;

import java.io.* ;
import java.sql.* ;
import java.util.* ;
import java.util.Date ;

import kwe.db.*;

/**
* ¹ÜÀíÀàSqlServerÖ§³Ö¶ÔÒ»¸ö»ò¶à¸öÓÉÊôÐÔÎļþ¶¨ÒåµÄÊý¾Ý¿ Á¬½Ó
* ³ØµÄ·ÃÎÊ.¿Í»§³ÌÐò¿ÉÒÔµ÷ÓÃgetInstance()·½·¨·ÃÎʱ¾ÀàµÄΨһʵÀý.
*/
public class SqlServer
{
static private SqlServer instance ; // ΨһʵÀý
static private int clients ;

private Vector drivers = new Vector() ;
private PrintWriter log ;
private Hashtable pools = new Hashtable() ;

//cuiqi add the cache --2003-12-22
private HashMap cachedValueHash = new HashMap();
private HashMap cachedUnitCDHash = new HashMap();
private HashMap cachedUnitInfo = new HashMap();
//end of add

//add for new arrival -- 2003-12-26
private Vector newArrivals = new Vector();

//add for domestic logistic temp worker -- 2003-01-05
private Vector logisticTemps = new Vector();

//add for store all who have year bonus -- 2004-01-06
private Vector yearBonusTable = new Vector();

private Vector outerManTable = new Vector();

private HashMap cachedOuterBonusHash = new HashMap();

private Vector foreignerTable = new Vector();

//end of add -- 2004-01-06

//add for cache 2004-01-08
private String salaryListCD;

/**
* ·µ»ØÎ¨Ò»ÊµÀý.Èç¹ûÊǵÚÒ»´Îµ÷Óô˷½·¨,Ôò´´½¨ÊµÀý
*
* @return SqlServer ΨһʵÀý
*/
static synchronized public SqlServer getInstance(String dateYM)
{
if(instance == null)
{
instance = new SqlServer(dateYM) ;
}
clients++ ;
return instance ;
}

/**
* ½¨¹¹º¯Êý˽ÓÐÒÔ·ÀÖ¹ÆäËü¶Ô¡¦´´½¨±¾ÀàʵÀý
* Note: add the para "dateYM" to make the new arrival visible to sqlserver --2003-12-26
*/
private SqlServer(String dateYM)
{
init(dateYM) ;
}

/**
* ½«Á¬½Ó¶Ô¡¦·µ»Ø¸øÓÉÃû×ÖÖ¸¶¨µÄÁ¬½Ó³Ø
*
* @param name ÔÚÊôÐÔÎļþÖж¨ÒåµÄÁ¬½Ó³ØÃû×Ö
* @param con Á¬½Ó¶Ô¡¦
*/
public void freeConnection(String name,Connection con)
{
DBConnectionPool pool = (DBConnectionPool)pools.get(name) ;
if(pool != null)
{
pool.freeConnection(con) ;
//kwe.System.out.println("free connection ok");
}
}

/**
* »ñµÃÒ»¸ö¿ÉÓõÄ(¿ÕÏеÄ)Á¬½Ó.Èç¹ûûÓпÉÓÃÁ¬½Ó,ÇÒÒÑÓÐÁ¬½ÓÊýСÓÚ×î´óÁ¬½ÓÊý
* ¡¦ÖÆ,Ôò´´½¨²¢·µ»ØÐ Á¬½Ó
*
* @param name ÔÚÊôÐÔÎļþÖж¨ÒåµÄÁ¬½Ó³ØÃû×Ö
* @return Connection ¿ÉÓÃÁ¬½Ó»ònull
*/
public Connection getConnection(String name)
{
DBConnectionPool pool = (DBConnectionPool)pools.get(name) ;
if(pool != null)
{
return pool.getConnection() ;
}
return null ;
}

/**
* »ñµÃÒ»¸ö¿ÉÓÃÁ¬½Ó.ÈôûÓпÉÓÃÁ¬½Ó,ÇÒÒÑÓÐÁ¬½ÓÊýСÓÚ×î´óÁ¬½ÓÊý¡¦ÖÆ,
* Ôò´´½¨²¢·µ»ØÐ Á¬½Ó.·ñÔò,ÔÚÖ¸¶¨µÄʱ¼äÄڵȴýÆäËü¡¦³ÌÊÍ·
   

- Advertisement -