Spring opens 1 DB connection but yk shows 2

Questions about YourKit Java Profiler
Post Reply
mmoossen
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Spring opens 1 DB connection but yk shows 2

Post by mmoossen »

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
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Post by Anton Katilin »

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
mmoossen
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Re: Spring opens 1 DB connection but yk shows 2

Post by mmoossen »

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
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Post by Anton Katilin »

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: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Post by Anton Katilin »

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.
mmoossen
Posts: 3
Joined: Fri Oct 14, 2011 11:48 am

Re: Spring opens 1 DB connection but yk shows 2

Post by mmoossen »

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.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Spring opens 1 DB connection but yk shows 2

Post by Anton Katilin »

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.
Post Reply