开发者

Spring JDBC vs JDBC

I have been trying to use spring 3.0 Sim开发者_高级运维pleJdbcTemplate and it takes 5 mins to insert 1500 records, whereas it take me a few secs. to insert using straight JDBC. Not sure what I am doing wrong.


If you are building batch consider using Spring batch - JdbcBatchItemWriter with proper chunk size settings, that will load these 1500 records in less than a second.


Some things worth checking:

  • The overhead might be on the transaction managed by Spring at the application level. Look what kind of transaction manager you are using (look for a bean with name transactionManager). If you are using JTA, that's probably where your problem is. Since it's fast with JDBC the bottleneck doesn't seem to be the db.
  • Depending on how your app is using that transaction, it might be holding everything in memory before it finishes all 1500 requests and commits. Do you see a large difference in memory usage (the Spring one should be a lot higher)?
  • What kind of DB connection pool are you using in either of the cases?

Quick way to profile your app:

Get the pid - "jps -l"

Memory: jmap -histo PID (check if there's some form of memory leak)

Check what's going on under the hood: jstack PID (look for slow or recursive method calls)


How about using

jdbcTemplate.batchUpdate(new String[]{sql}); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜