在Java中以一定的时间间隔添加大量数据

编程入门 行业动态 更新时间:2024-10-14 08:29:27
本文介绍了在Java中以一定的时间间隔添加大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用jdbc在一段时间内添加数据库表中的记录.

I want to add records I database table with some interval of time using jdbc.

例如,我想以10秒的间隔添加100000条记录,以便它每秒插入10000条.

For ex., I want to add 100000 records in 10 sec interval so it'll insert 10000/sec.

我的MySQL代码如下:

My code of MySQL as below :

String url1 = "jdbc:mysql://localhost:3306/xyz"; String user = "root"; String password = "root"; conn1 = DriverManager.getConnection(url1, user, password); if (conn1 != null) { System.out.println("Connected to the database xyz"); for(int i=0;i<=n;i++){ // where n is no. of record that I want to insert // Here is my insert logic } }

推荐答案

@ yogesh-jalodara在我的评论中,我的意思是这样的

@yogesh-jalodara In my comments I meant something like that

final long loopDuration = 1;//second final long totalSize = 100000; final long timeInterval = 10; final AtomicLong batchNumber = new AtomicLong((long)Math.ceil((double) timeInterval / loopDuration)); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { //insert logic if (batchNumber.decrementAndGet() == 0) { timer.cancel(); timer.purge(); } } }, 0, loopDuration * 1000);

更多推荐

在Java中以一定的时间间隔添加大量数据

本文发布于:2023-11-22 03:48:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   中以   时间   数据   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!