java分批处理10万数据_Java模拟数据量过大时批量处理数据的两种实现方法

方法一:

代码如下:

import java.util.ArrayList;

import java.util.List;

/**

* 模拟批量处理数据(一)

* 当数据量过大过多导致超时等问题可以将数据进行分批处理

* @author 【】

*

*/

public class BatchUtil2 {

public static void listBatchUtil(List lists) {

System.out.println(lists);

System.out.println(lists.size());

int temp = 1;

for (int i = 0; i < lists.size(); i += 10) {

System.out.println("======================进行第" + temp + "次批处理=======================");

if (lists.size() - i > 10) {

System.out.println(lists.subList(i, i + 10).toString());

} else {

if (lists.size() > i) {

System.out.println(lists.subList(i, lists.size()).toString());

}

}

temp += 1;

}

}

public static void main(String[] args) {

List lists = new ArrayList<>();

for (int i = 1; i <= 26; i++) {

lists.add(i);

}

listBatchUtil(lists);

}

}

实现效果:

3e9855af03a43cc98f433073443f5716.png

方法二:

代码如下:

import java.util.ArrayList;

import java.util.List;

/**

* 模拟批量处理数据(二)

* 当数据量过大过多导致超时等问题可以将数据进行分批处理

* @author 【】

*

*/

public class BatchUtil {

public static void listBatchUtil(List lists) {

System.out.println(lists);

// 定义批处理的数据数量(即批处理条件)

int num = 10;

// 判断集合数量,如果小于等于定义的数量(即未达到批处理条件),直接进行处理

if (lists.size() <= num) {

System.out.println(lists.size());

System.out.println(lists.toString().substring(1, lists.toString().lastIndexOf("]")));

return;

}

// 如果大于定义的数量,按定义数量进行批处理

int times = lists.size()/num + 1;

System.out.println("一共要进行"+times+"次批处理");

// 遍历分批处理次数,并进行批处理

for (int i = 0; i < times; i++) {

// 定义要进行批处理的临时集合

List tempList = new ArrayList<>();

// 将要批处理数据放入临时集合中

for (int j = i*num; j < lists.size(); j++) {

tempList.add(lists.get(j));

if (tempList.size() == num) {

break;

}

}

// 进行批处理

System.out.println("======================进行第"+(i+1)+"次批处理=======================");

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 lists = new ArrayList<>();

for (int i = 1; i <= 26; i++) {

lists.add(i);

}

listBatchUtil(lists);

}

}

实现效果:

6368e29710f4a2c2e8e8e90ab02ccef1.png

EasyExcel 低内存导出大数据量的Excel方案探索 50万行 50列 (附:实现代码) 最近接到一个需求,需要从服务器中导出大量数据到Excel中,数据量大概为50万行,50列,借助这个机会,就想对使用使用低内存导出大数据量的方案进行探索,总结出一个通用可行性方案,以方便日后随时可以使用,同时也分享一下探索的过程。降低存入到内存中的数据,使用分批次查询、分批次插入数据的方式。尽可能的减少并发,避免使用多线程操作Excel,同时,还可以通过队列做异步和限流,排队处理导出请求。考虑到Excel文件过大无法操作,可以将一个大文件拆分为多个小文件。 阅读详情

相关推荐

Java实现大数据量生成与数据库批量插入实战脚本

技术作用预编译,防注入,执行计划缓存减少网络往返减少事务提交开销合并为多值 INSERT,降低解析成本该组合在实测中可实现每秒 5~8 万条插入(取决于硬件与索引情况)。严禁在生产主库上直接执行大规模写入操作,可能引发以下问题:锁表阻塞线上查询binlog 日志暴增导致磁盘满主从延迟严重,影响灾备切换建议在专用压测库或从库脱敏后环境中运行。

weixin_42600407的博客 1095

java线程池的使用,实现大量数据的更新操作

在大量数据更新处理时,单个线程的执行速度过于缓慢,使用多线程可以大幅度的提高执行速度,下面我们来看看具体如何使用java线程池。 第一步,创建一个线程池(单例),用于实例化线程池,记录线程执行相关信息。package com.qiyongkang.thread.threadpool.test2.common;import java.util.ArrayList; import java.util.H

蛋导的平凡之路 6447

java一次性查询处理几百万数据解决方法

java一次性查询处理几百万数据解决方法 几百万数据是可以处理的 暂时还没试过几千万级的数据处理

java 批处理 大量数据的增删改

java 快速处理超大数据的增删改

qq_40426135的博客 2198

扣子(coze)案例^第22期:零代码打造小红书竞品监控系统+AI自动生成运营策略建议

本文详细介绍了如何利用扣子(coze)平台零代码搭建小红书竞品监控系统。该系统通过自动化工作流抓取竞品笔记数据,并存入飞书多维表格,结合AI能力自动生成包含可视化分析报告在内的运营策略建议,帮助运营者高效进行数据驱动的市场分析。

weixin_29313239的博客 1004

华为昇腾 910B 实战:DeepSeek-R1 蒸馏模型高效部署与性能调优全解析

本文详细解析了在华为昇腾910B硬件平台上高效部署DeepSeek-R1蒸馏系列模型(14B/32B版本)的完整实战流程。内容涵盖从MindIE环境搭建、镜像获取、模型准备,到服务配置、内存参数调优、性能测试及常见问题排查,为开发者提供了基于昇腾910B进行大模型部署与优化的全链路指南。

weixin_28235513的博客 210

mybatisPlus百万数据量批量插入

大数据量批量插入、更新优化方法

m0_47743175的博客 1610

深信服上网行为管理设备登录方法、恢复出厂、恢复控制台密码

1.初识设备 1.1 设备外观 1.2 软件版本 2.如何登录设备 首次拿到AC/SG设备时,可以通过以下方法登录设备控制台 SANGFOR AC/SG设备,各网口默认的出厂IP为: eth0(LAN):10.251.251.251/24 , eth1(DMZ)10.252.252.252/24 1、使用一根交叉线连接设备和电脑 (1) 如果电脑连接的是设备的eth0口,需先在电脑上配...

✍千里之行,始于足下 ^,^ 5万+

多线程处理十万百万级List(大list处理)

一、背景 对于java开发中,十万百万级别的list进行各种操作,然后入库等操作好多时候会遇到。普通单线程处理,处理时间长,还经常报gc问题。针对此问题,查阅了网上很多资料,好多都使用多线程来处理。跟着好多的博客进行处理,要么是线程安全问题,要么根本速度就提高不了。我针对我项目中的使用场景,结合资料进行了修改,特提交此文,为有共同需求的小伙伴提供一点建议。 本次使用场景为:从数据库中查阅数十万数据生成list,将list进行遍历转json,拼接属性,组转成新list批量入库es. ...

qq_28025423的博客 1万+

别再死磕AUTOSAR文档了!手把手教你用ISOLAR-A配置BswM模块(附实战流程图)

本文通过Vector ISOLAR-A工具实战演示AUTOSAR BswM模块的配置流程,帮助工程师快速掌握基础软件模式管理。从环境准备到模式仲裁规则配置,再到动作列表实现,详细讲解每个步骤,并提供常见问题排查和高级优化技巧,大幅提升开发效率。

weixin_42542669的博客 248

pgsql:还原数据库后出现重复序列导致“more than one owned sequence found“报错问题的解决

pgsql数据库通过备份数据库文件进行还原时,如果表中有自增序列,还原后可能会出现重复的序列,此时若向表中插入新行时会出现“more than one owned sequence found”的报错提示。还原数据库时把序列取消勾选,选择不还原序列。因为还原表的同时,会自动将自增序列还原上去,此处勾选会导致数据库重复创建序列。点击还原数据库完毕后,可以看到序列仅有一个,没有出现重复序列。但此时的序列当前值是从1开始的,需要重置。点击菜单“其它”-》“序列”,可以看到有多个重复序列。

奋斗鱼 1043

java 批量处理_Java模拟数据量过大时批量处理数据的两种实现方法

方法一:代码如下:import java.util.ArrayList;import java.util.List;/*** 模拟批量处理数据(一)* 当数据量过大过多导致超时等问题可以将数据进行分批处理* @author 【】**/public class BatchUtil2 {public static void listBatchUtil(List lists) {System.out.p...

weixin_35859336的博客 2855

结构设计3D拆件与骨架模型构建实战:基于Creo 8.0的5个高效建模技巧

本文详细解析了基于Creo 8.0的结构设计3D拆件与骨架模型构建实战技巧,涵盖5个高效建模方法,包括参数化驱动、曲面分割、多实体协同设计等。通过骨架模型的智能应用,设计效率可提升30%以上,特别适合复杂产品的结构设计。文章还提供了TWS耳机充电仓等实战案例,帮助工程师快速掌握工业设计中的核心建模技术。

weixin_30000735的博客 570

Java模拟数据量过大时批量处理数据的两种实现方法

方法一:   代码如下:  import java.util.ArrayList; import java.util.List; /** * 模拟批量处理数据(一) * 当数据量过大过多导致超时等问题可以将数据进行分批处理 * @author 【】 * */ public class BatchUtil2 { public static void...

a54325的博客 1285

Android 13.0 framework默认沉浸式导航栏功能实现

​ 在13.0的系统rom定制化开发中,在实现导航栏的某些定制化开发中,在某些产品需要实现沉浸式导航栏,就是需要app 能全屏显示同样也能显示导航栏,接下来就来分析下相关的功能实现 ​

安卓兼职framework和app工程师的博客 467

标准测试测试数据STDF学习笔记

本文介绍了STDF(Standard Test Data Format)文件的结构与解析方法。首先详细说明了STDF记录的组成,包括记录头类型(REC_TYP和REC_SUB)、数据类型定义、时间日期格式以及无效数据标识。重点分析了25种主要记录类型的功能、数据内容和出现位置,如FAR、MIR、MRR等关键记录。然后介绍了基于pystdf开源工具的解析方法,包括自带脚本的使用和自编程解析流程,通过事件驱动机制处理数据流。特别指出测试数据是按照PIR→PTR/MPR/FTR→PRR的循环模式组织。文章为ATE

歌颂苦难的行为是无耻的; 1513

java 批量处理数据_Java模拟数据量过大时批量处理数据实现

代码:import java.util.ArrayList;import java.util.List;/*** 模拟批量处理数据* 当数据量过大过多导致超时等问题可以将数据进行分批处理* @author 【】**/public class BatchUtil {public static void listBatchUtil(List lists) {System.out.println(lis...

weixin_28987465的博客 402

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

多线程分批处理数据及MyBatis的批量插入

多线程分批处理时,那如何分批,怎么计算批次数呢? MyBatis批量插入示例

一个喜欢诗和远方的程序媛 4347

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Springboot 多线程分批切割处理 大数据量List集合 ,实用示例

Springboot 多线程分批切割处理 大数据量List集合 ,实用示例

默默不代表沉默 6974

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java批量处理数据_Java批量处理数据

要求:共1000条数据,第一次批量插入100条,第二次批量插入101到200条,依次插入数据;实现方式这里选择了两种常用的方式,都是使用List操作;第一种实现思路如下:<1> 原先存放数据的List为recordList,求出共需批量处理的次数;<2> 新建一个List为list,循环后,将recordList的前maxValue条数据放到list里;<3> ...

weixin_42501704的博客 4785

mybatis for循环批量插入及分批插入

文章目录前言批量插入原因stackOverFlowError临界值解决办法改变栈大小(不推荐)分批插入 前言 背景是这样的,在一次多个系统数据同步的时候,数据量较大,一次大概5000条,在同步的时候我采用的批量插入的方法,模拟测试没问题,但是实际测试却爆出了stackOverFlowError异常,于是乎,跟了一波代码, 批量插入 DAO void insertList(List<Object> listData); Mapper <insert id="insertList" par

qq_42726668的博客 4745

Java分批处理数据,如何保证数据的顺序?

在实际开发中,面对大数据量的处理场景时,我们常常会采用“分批处理(Batch Processing)”的方式,避免一次性加载全部数据造成OOM(内存溢出)等问题。然而,,却是一个非常实用且有挑战性的问题。

Wanankl的博客 1456

Stream 大数据量List分批处理 java8

数据量大的 List中,如果要操作数据库 ,可以分批次,比如一次500的数据 public static void main(String[] args) { //模拟模拟 List<ReceiptMethodIdAndNameBean> paperNoList = new ArrayList(); for (int i = 0; i < 1000; i++) { ReceiptMethodIdAndNameBea

TimerShaft的博客 1538
上一篇: 基于php mysql的网站开发_基于PHP+MySQL校园网站的设计与实现
下一篇: 三羊献瑞 蓝桥杯java_蓝桥杯-三羊献瑞
小欣意小欣意
博客等级 码龄8年 40粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值