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