Implementation of batch processing data when Java analog data volume is too large

Source: Internet
Author: User

Code:

Import Java.util.arraylist;import java.util.list;/** * Simulate batch processing data * When too much data is too large to cause problems such as timeouts can be processed in batches * @author "" * */public class batchutil {public static void Listbatchutil (List<integer> lists) {System.out.println (lists);// Defines the number of batches of data (that is, batch conditions) int num = 10;//determines the number of sets, if the number is less than or equal to the defined quantity (that is, the batch condition is not reached), directly processes if (lists.size () <= num) {System.out.println ( Lists.size ()); System.out.println (lists.tostring (). substring (1, lists.tostring (). LastIndexOf ("]")); return;} batch int times = Lists.size ()/num + 1 If the quantity is greater than the defined quantity; System.out.println ("A total of" +times+ "batches");//traverse batch processing times and batch for (int i = 0; I < times; i++) {//define a temporary collection to be batched list<in teger> templist = new arraylist<> ();//To put the batch data into a temporary collection for (int j = I*num; J < Lists.size (), j + +) {Templist.add ( Lists.get (j)); if (templist.size () = = num) {break;}} Batch processing System.out.println ("======================" + (i+1) + "sub-batch ======================="); System.out.println (Templist.size ()); System.out.println (templist.tostring (). substring (1, templist.tostring ().LastIndexOf ("]")); System.out.println ("=========================================================");}} public static void Main (string[] args) {list<integer> lists = new arraylist<> (), for (int i = 1; I <=; i+ +) {Lists.add (i);} Listbatchutil (lists);}}

Implementation results:

Implementation of batch processing data when Java analog data volume is too large

Related Article

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.