A performance issue that is encountered with spring JDBC

Source: Internet
Author: User

Using the JdbcTemplate queryForList method, the return is particularly slow, and the more than 400,000 result set takes more than 6 minutes. Dual-core CPU, the occupancy rate is always at 50%, the memory gradually increases to about 2G.

Debug follow up to see, see JdbcTemplate call JDBC returned resultset only 30 seconds or so, and then have been consumed in the Extractdata method. The method is to use the default RowMapper, first get metadata and then based on this to generate map.

Comparison method:

1. Using pure JDBC contrast, manual code codes, directly call map put method to generate map and populate data. The same SQL, which takes more than 40 seconds, the last memory 2G, which generates list<map<string according to ResultSet, object>> process does not exceed 10s.

2. Use JdbcTemplate's public <T> list<t> query (String sql, Rowmapper<t> RowMapper) method, T fill in map<string, Object>, this is the same as the queryForList method return value, and then implement the rowmapper yourself, and directly populate the data with the map's put method. The experimental results are the same as that of pure JDBC directly.

3. Using pure JDBC, write an entity class yourself and put the data in the ResultSet into the list by filling in the object. It takes more than 40 seconds and the last memory is 1.5G. The explanation still saves a bit of memory. But performance gains are limited.


Conclusion:

At present, it is advisable to use the public <T> list<t> query (String sql, rowmapper<t> RowMapper) method instead of the Qeuryforlist method when the result set is large. This will improve efficiency.


Future estimates of JdbcTemplate's queryforlist efficiency will also rise to similar levels.

A performance issue that is encountered with spring JDBC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.