yogesh jalodara yogesh jalodara - 5 months ago 10x
SQL Question

Add lots of data with some time interval in Java

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

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

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 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() {
    public void run() {
        //insert logic
        if (batchNumber.decrementAndGet() == 0) {

}, 0, loopDuration * 1000);