Dbutil tutorial (4) buffer multi-thread insert

Source: Internet
Author: User

In some business systems, a large amount of data needs to be inserted into the database every minute. I am developing a NetFlow management system and receive more than several thousand data per minute in the database. Although the data volume is not large, it cannot be processed well, and the database may not be stable. If you need to insert so many SQL statements to the database every minute, many of my friends have proposed batch submission, and I also adopt related technologies. However, there is too much data. Each time only 1000 rows of data are submitted in the cache, the submission time is long and the database crashes.

Later, we proposed a new solution, that is, multi-threaded cache for data submission.

First, start 20 threads and wait for the task.

Then, the data is buffered. IF 1000 SQL statements are cached, the SQL statement is sent to the thread. The thread is not blocked and the operation is inserted into the main thread to continue waiting;

Package COM. shine. dbutil; public class batchexample {/*** batch submit ** @ Param ARGs */public static void main (string [] ARGs) {system. out. println ("batchexample... "); dbutil. getinstance (). init ("e :\\ workspace \ javaframework2.0 \ SRC \ com \ shine \ framework \ dbutil \ config \ dbxml. XML "); For (INT I = 0; I <5006; I ++) {// system. out. println (I); string SQL = "insert into test1 (TEST) value ('" + I + "')"; dbutil. getinstance (). addbatchupdate ("JDBC/test", SQL );}}}

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.