Java large collection data is cut in batches

Source: Internet
Author: User

Today encountered a large collection of data removal problems,

Because it is a large collection, if it is passed to the database at the same time, it will cause the database pressure

So batch operations are done in batches

In fact, you can use multithreading to deal with or multi-batch plus multi-threaded to deal with it is possible

The following case focuses on code that is a large collection split into small collections

Avoid the next use to forget!

Do not say anything, directly on the code, to avoid the next time will be used, first remember

 Public Static voidMain (string[] args) {List<String> list=NewArraylist<string>();  for(inti = 0; I <=100000; i++) {List.add (""+i); }          intSize=list.size (); intnum = (size)% 30 = = 0? (SIZE/30): (Size/30 + 1);//Search by every 30 records          intStart=0; intEnd =0; List<String> A =NewArraylist<string>(); //Method 1           for(inti = 1; I <= num; i++) {End= (i*30) > size? Size: (i*30); Start= (i-1) *30;  for(; start < end; start++) {A.add (List.get (start)); } System.out.println ("Output Data---" +a.tostring ()); //here can be processed data insert Modify Delete can be manipulated to avoid the simultaneous operation of large aggregate dataa.clear (); }         //Method 2End=0; Start=0;  for(inti = 1; I <= num; i++) {End= (i*30) > size? Size:(i*30); Start= (i-1) *30; System.out.println (End+"--"+start); A=list.sublist (start,end); System.out.println ("Output Data-bbb--" +a.tostring ()); }  }

Java large collection data is cut in batches

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.