Reputation: 742
I have a simple JDBC batch insert program. I am fetching data from one database table and inserting these records to a table in another database after processing. But the target database is having some performance issues. So the target db admin requests an option in our program to control the number of records inserted per second.
It may not be dynamic. If he wants to change the insert speed, he can change the config property accordingly and restart the application.
Our source and target databases are MQ SQL databases.
Is it possible?
Upvotes: 0
Views: 271
Reputation: 4413
You can put the thread to sleep once you've inserted your specified number of records.
int recordsPerSecond = 100;
int totalRecords = 1000;
long sleepTime = 900; // in milis (Assuming that 100 mili seconds lapsed in inserting 100 rows)
for(int i=1; i<=totalRecords; i++){
if(i%recordsPerSecond==0)
Thread.sleep(sleepTime);
DAO.insert();
}
Upvotes: 1