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