ultraman7719
asked on
It's Hang.. Connection pooling..
Bro Tim, i copyrighted your code.. hope you dont mind. But when i run it, until certain call [press refresh button], i will not able to see the data. Done some troubleshooting and see its hand in the DataSource part..
Anyone can spot what is happending? And also, when i down the tomcat, i have this message, seems it's still holding the connection...
********
Feb 21, 2006 12:16:34 PM org.apache.catalina.core.S tandardWra pper unload
INFO: Waiting for 2 instance(s) to be deallocated
Feb 21, 2006 12:16:35 PM org.apache.catalina.core.S tandardWra pper unload
INFO: Waiting for 2 instance(s) to be deallocated
Feb 21, 2006 12:16:36 PM org.apache.catalina.core.S tandardWra pper unload
INFO: Waiting for 2 instance(s) to be deallocated
******
Mycode:
..
public static int counter =0;
..
..
counter++;
DataSourceLocator ds = new DataSourceLocator();
Connection conn = ds.getConnection("jdbc/Tes tDB");
..
while (rs.next()) {
System.out.println(counter + " Model " + rs.getString("Model"));
System.out.println(counter + " Remark " + rs.getString("Remark"));
}
..
..
DataSourceLocator.java
===============
..
..
public DataSourceLocator() throws javax.naming.NamingExcepti on {
System.out.println("Initia lition");
jndiContext = new InitialContext();
dataSources = new HashMap();
}
public static DataSourceLocator getInstance()
throws javax.naming.NamingExcepti on {
return locator != null ? locator : (locator = new DataSourceLocator());
}
public Connection getConnection(String name) throws java.sql.SQLException,
javax.naming.NamingExcepti on {
System.out.println("Prepar ing connection");
System.out.println("Source s Map Size" + dataSources.size());
DataSource source = (DataSource) dataSources.get(name);
==>
if (source == null) {
source = locateDataSource(name);
} else {
System.out.println("Connec tion is " + source.getConnection().toS tring());
}
===>
return source.getConnection();
}
synchronized private DataSource locateDataSource(String name)
throws javax.naming.NamingExcepti on {
System.out.println("Lookin g for DataSource");
DataSource source = (DataSource) dataSources.get(name);
if (source == null) {
source = (DataSource) jndiContext.lookup("java:c omp/env/" + name);
Map newSources = new HashMap(dataSources);
newSources.put(name, source);
dataSources = newSources;
} else {
System.out.println("DataSo urce HashCode " + source.hashCode());
}
System.out.println("source " + source.toString());
return source;
}
..
..
this is the output...it's hang in "==>" shown above..
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
1 Model Iswara
1 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
2 Model Iswara
2 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
3 Model Iswara
3 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
4 Model Iswara
4 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
5 Model Iswara
5 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
6 Model Iswara
6 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
7 Model Iswara
7 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Preparing rs.net()
8 Model Iswara
8 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
Anyone can spot what is happending? And also, when i down the tomcat, i have this message, seems it's still holding the connection...
********
Feb 21, 2006 12:16:34 PM org.apache.catalina.core.S
INFO: Waiting for 2 instance(s) to be deallocated
Feb 21, 2006 12:16:35 PM org.apache.catalina.core.S
INFO: Waiting for 2 instance(s) to be deallocated
Feb 21, 2006 12:16:36 PM org.apache.catalina.core.S
INFO: Waiting for 2 instance(s) to be deallocated
******
Mycode:
..
public static int counter =0;
..
..
counter++;
DataSourceLocator ds = new DataSourceLocator();
Connection conn = ds.getConnection("jdbc/Tes
..
while (rs.next()) {
System.out.println(counter
System.out.println(counter
}
..
..
DataSourceLocator.java
===============
..
..
public DataSourceLocator() throws javax.naming.NamingExcepti
System.out.println("Initia
jndiContext = new InitialContext();
dataSources = new HashMap();
}
public static DataSourceLocator getInstance()
throws javax.naming.NamingExcepti
return locator != null ? locator : (locator = new DataSourceLocator());
}
public Connection getConnection(String name) throws java.sql.SQLException,
javax.naming.NamingExcepti
System.out.println("Prepar
System.out.println("Source
DataSource source = (DataSource) dataSources.get(name);
==>
if (source == null) {
source = locateDataSource(name);
} else {
System.out.println("Connec
}
===>
return source.getConnection();
}
synchronized private DataSource locateDataSource(String name)
throws javax.naming.NamingExcepti
System.out.println("Lookin
DataSource source = (DataSource) dataSources.get(name);
if (source == null) {
source = (DataSource) jndiContext.lookup("java:c
Map newSources = new HashMap(dataSources);
newSources.put(name, source);
dataSources = newSources;
} else {
System.out.println("DataSo
}
System.out.println("source
return source;
}
..
..
this is the output...it's hang in "==>" shown above..
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
1 Model Iswara
1 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
2 Model Iswara
2 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
3 Model Iswara
3 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
4 Model Iswara
4 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
5 Model Iswara
5 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
6 Model Iswara
6 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
7 Model Iswara
7 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
Preparing rs.net()
8 Model Iswara
8 Remark BUKIMAK
Initialition
Preparing connection
Sources Map Size0
Looking for DataSource
source org.apache.tomcat.dbcp.dbc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and is it that the main reason causing the system hang??
you need to close them to tell the pool you are no longer using them.
Otherwise they cannot be reused, defeating the need for a pool in the 1st place
Otherwise they cannot be reused, defeating the need for a pool in the 1st place
ASKER
object, you are right.. after i have included the close() command in, it's working fine. HAHAH..
by the way, how am i make sure tat it's realy using the connection pool??
i have tri to observed the total connection to Mysql in the MySql Network connection, it's seems the counter is keep on increasing each time i load the page... how can i make sure or observed so that i can prove to the team of my people....
by the way, how am i make sure tat it's realy using the connection pool??
i have tri to observed the total connection to Mysql in the MySql Network connection, it's seems the counter is keep on increasing each time i load the page... how can i make sure or observed so that i can prove to the team of my people....
ASKER
and also.. if i didnt close the connection, how come it's only can stand up to 8 connection and it'll hang there? the MySQL setting i put is able to hold up to 20 connection...
Any other place i can set?
Any other place i can set?
Whats the pool settings ie. how many connections does it have?
ASKER
i didnt include anything connection limit in the server.xml file. ( Is there where i should set the Max Connection)??
<Context
crossContext="true"
docBase="C:/Documents and Settings/Foong/workspace/C onnectionP oolTest"
path="/ConnectionPoolTest"
reloadable="true"
workDir="C:\Documents and Settings\Foong\workspace\C onnectionP oolTest\wo rk">
debug="5"
<Resource
auth="Container"
name="jdbc/TestDB"
type="javax.sql.DataSource "
driverClassName="com.mysql .jdbc.Driv er"
password="password"
username="root"
url="jdbc:mysql://localhos t:3306/foo ngtest"/>
</Context>
>>by the way, how am i make sure tat it's realy using the connection pool??
Object, i have tried to observed in the MySQL admin console. i can see the different alreday...
<Context
crossContext="true"
docBase="C:/Documents and Settings/Foong/workspace/C
path="/ConnectionPoolTest"
reloadable="true"
workDir="C:\Documents and Settings\Foong\workspace\C
debug="5"
<Resource
auth="Container"
name="jdbc/TestDB"
type="javax.sql.DataSource
driverClassName="com.mysql
password="password"
username="root"
url="jdbc:mysql://localhos
</Context>
>>by the way, how am i make sure tat it's realy using the connection pool??
Object, i have tried to observed in the MySQL admin console. i can see the different alreday...
ASKER
Object, one things i curious.. i tot i have to use "Singleton" class to do the connection pooling, but seemsi am not using any Singleton class also yet i can share the pool...
so, which approach is a beter approach?
so, which approach is a beter approach?
> Object, i have tried to observed in the MySQL admin console. i can see the different alreday...
the class of the connection should also be differnt I'd say
the class of the connection should also be differnt I'd say
ASKER
how can i see the "class"?
System.out.println(source. getConnect ion().getC lass());
> source org.apache.tomcat.dbcp.dbc p.BasicDat aSource@3d fcb
you can already see here that you are using dbcp data sources
you can already see here that you are using dbcp data sources
ASKER
the connection setting that you have mentioned.. where can i specified it?
in the server.xml?
in the server.xml?
ASKER
if i include it (close connection) in, then the other coming in to get the connection will not able to get it right?