Fully featured low overhead profiler for Java EE and Java SE platforms.
Performance monitoring and profiling of Jenkins, TeamCity, Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

Spring opens 1 DB connection but yk shows 2

Moderators: Vladimir Kondratyev, Anton Katilin

Spring opens 1 DB connection but yk shows 2

Postby mmoossen » Fri Oct 14, 2011 11:56 am

Dear all,

Spring opens a connection for my statement and closes it later, yk correctly shows it. BUT it also shows a 2nd connection and tells that it is even open.

for further discussion and source code of test cases see:
http://forum.springsource.org/showthrea ... g-only-one

i could also provide a snapshot if needed. (could not find how to upload files here)

thanks
Michael
mmoossen
 
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Re: Spring opens 1 DB connection but yk shows 2

Postby Anton Katilin » Mon Oct 17, 2011 12:57 pm

Hello Michael

Could you please provide snapshot demonstrating the problem.

ftp://upload.yourkit.com/pub/
user ftp
empty password

If you believe that the connection actually closes, but the profiler does not show it as closed, perhaps the connection is not closed via public method close() of Connection interface, thus the event cannot be caught by the built-in probe.

Best regards,
Anton
Anton Katilin
 
Posts: 5710
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Postby mmoossen » Mon Oct 17, 2011 1:47 pm

Hi Anton.

Thank for the reply.

If you believe that the connection actually closes, but the profiler does not show it as closed, perhaps the connection is not closed via public method close() of Connection interface, thus the event cannot be caught by the built-in probe.

As said, my connection is shown correctly. but a 2nd connection is shown, additionally as kept open.
see (and try) my simple testcase.

Could you please provide snapshot demonstrating the problem.

uploaded: tomcat-14-10-2011.snapshot

thanks
Michael
mmoossen
 
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Re: Spring opens 1 DB connection but yk shows 2

Postby Anton Katilin » Mon Oct 17, 2011 2:09 pm

Thank you for the snapshot.

There are many database connections created in the following stack:

java.sql.DriverManager.getConnection(String, Properties)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(String, Properties)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(Properties)
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(String, String)
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection()
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSource)
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSource)
org.springframework.jdbc.core.JdbcTemplate.execute(PreparedStatementCreator, PreparedStatementCallback)
org.springframework.jdbc.core.JdbcTemplate.query(PreparedStatementCreator, PreparedStatementSetter, ResultSetExtractor)
org.springframework.jdbc.core.JdbcTemplate.query(String, PreparedStatementSetter, ResultSetExtractor)
org.springframework.jdbc.core.JdbcTemplate.query(String, Object[], ResultSetExtractor)
org.springframework.jdbc.core.JdbcTemplate.query(String, Object[], RowMapper)
....


It seems that Connection.close() method is never called for them, otherwise it would have been caught by the built-in probe.

Are you familiar with how/where spring closes that connection, obtained via java.sql.DriverManager.getConnection(String, Properties) ?
Anton Katilin
 
Posts: 5710
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Postby Anton Katilin » Mon Oct 17, 2011 2:19 pm

P.S.

You use Spring version 2.5.6, right?
If so, please try the latest version 3.0. Perhaps it does not have this problem.
Anton Katilin
 
Posts: 5710
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Postby mmoossen » Wed Oct 19, 2011 12:00 pm

i did step-by-step debug the whole spring code and i can ensure you that spring does really and correctly open and close only one connection.

yourkit10 also shows correctly this connection, but also shows one additional open connection, that does not execute any statement nor even tries to connect to db.

this is definitively no spring issue.
mmoossen
 
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Re: Spring opens 1 DB connection but yk shows 2

Postby Anton Katilin » Wed Oct 19, 2011 12:54 pm

Hi,

The probes are very simple: they instrument methods which create the connection and the connection's close() method.

The unclosed connection has been recorded as created in
Code: Select all
java.sql.DriverManager.getConnection(String, Properties)
org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(String, Properties)


The object returned from that method is of a class which implements Connection interface. The method "void close()" has never been called for that instance, otherwise the connection would have been shown as closed.

OK, if you say that close() method has been called (at which stack?), the probe might have missed it if:
- the particular Connection class's close() method has not been instrumented for some reason. What is the exact actual class of that connection instance? Can you send its class file?
- the connection was closed via different method instead of the public interface method e.g. directly calling some implementation-specific closeImpl() or whatever.
Anton Katilin
 
Posts: 5710
Joined: Wed Aug 11, 2004 8:37 am


Return to Java Profiler

Who is online

Users browsing this forum: No registered users and 19 guests