Spring DAO - first query with JdbcTemplate takes much longer time

前端 未结 3 813
天命终不由人
天命终不由人 2021-01-20 18:32

In my application I use Spring MVC with DAO pattern to access MSSql database with JdbcTemplate. Everything is working fine but I have noticed that first query takes a bit lo

相关标签:
3条回答
  • 2021-01-20 19:16

    Your DataSource is a connection pool. The first query needs to connect. Subsequent queries reuse the connection. You could either configure dbcp to pre-create a few connections or connect and release manually right after the app starts.

    0 讨论(0)
  • 2021-01-20 19:20

    Have a look at the javadoc and source. getExceptionTranslator() probably involves some work to set up. Maybe you can control when that work happens with the lazy-init parameter.

    0 讨论(0)
  • 2021-01-20 19:29

    I checked that connection pool and its connections (initialSize) are created during first call when connection is needed, and then later it is reused in all requests, this is how it should work :), I have also noticed that 400ms time is lower (about 100ms) when there are multiple requests at the same time. I think the reason for initial longer time is because of establishing a TCP connection as John Watts mentioned or because of some Spring background management.

    0 讨论(0)
提交回复
热议问题