tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <>
Subject Re: Tomcat7 - ajax and connection pool : "connection closed" despite the use of "validationQuery" and "testOnBorrow"
Date Fri, 05 Apr 2013 11:09:46 GMT
2013/4/5 Jean-Claude Haw-King-Chon <>:
> Hi,
> I use the connection pool of tomcat7 and set a connection in a ThreadLocal.
> The context is a web application : the threadLocal is configured when the
> http request is initialized. The jdbc connection is closed and removed from
> the threadLocal when the resquest is destroyed.

1. What exactly do you mean by "initialized" and "destroyed"?

> If I'm not mistaken, each http request is treated by one thread by tomcat.
> So, I have one jdbc connection for each request ( = thread).

2. No.  It depends on how you use it and at what points in time you look at it.

If you look at it in a call chain, e.g. using try{ } finally block in
a Filter, then yes, all calls inside of "try" belong to the same

If you return processing to Tomcat and Tomcat makes a different call
into your code (e.g. using Async or Comet APIs), then that call can be
using a different thread from a thread pool.

> (...)
> My problem appears when I use Ajax. For 2 successive ajax request, I have
> the error "Connection closed" : it's a random problem (the stacktrace is not
> the same for the 2 attemps and it's not depending of the thread execution
> order).
> I know this issue :
> "These can occur when one request gets a db connection from the connection
> pool and closes it twice. When using a connection pool, closing the
> connection just returns it to the pool for reuse by another request, it
> doesn't close the connection. And Tomcat uses multiple threads to handle
> concurrent requests"
> But, I'm sure, I always close the connection only once.
> I use too the "validationQuery" and "testOnBorrow" parameters.
> Is it possible that the connection pool returns the same connection for 2
> different threads?

You can check its hash code.

> So I don't understand why my connection is closed during the treatment.

Best regards,
Konstantin Kolinko

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message