A solution for JDBC memory overflow

Source: Internet
Author: User

I went to the company the day before, and the boss said, "All servers are down!

After troubleshooting for half a day, the conclusion is that memory overflow!

In the was dump log, I was dizzy and finally found the culprit. It turned out that a colleague used a scrollable result set when writing code, leading to memory overflow.

What is a scrollable result set? Actually, it is the resultset cursor. Originally, Oracle does not support the cursor to move up. It can only move down, that is, generally used Rs. next (), but the JDBC interface and driver provide a move-up cursor, which obviously means that the cursor is implemented in Java. I have not read the source code, but I guess, when the cursor moves to the next row, the obtained records are saved to a collection. If you need to call the previous one, you can get the previous data.

This implementation is not controversial, but you should pay attention to the scenario. If you can ensure that your data volume is not large, it is more than enough to store thousands of data records into the collection, however, if you are not sure about the data volume, for example, if you want to export the report data, this report may only contain more than one thousand records, but you do not know how many records, tens of thousands or even millions, storing millions of business data in a list set obviously results in memory overflow !!

Therefore, it is recommended that you do not use a scrollable result set to process business logic that you do not know the amount of data. The price is that the server may be dumped due to memory overflow !!

That is, when constructing a statement object, try not to add

Resultset. type_scroll_insensitive

Resultset. type_scroll_sensitive

These can make the result set scroll!

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.