0

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?

4
  • 1
    Yes, it is possible. But it's also odd. Commented Sep 9, 2014 at 16:49
  • 1
    Throttling any sequence of commands isn't necessarily difficult.. I'm not sure I know what you're asking for advice on. It would just be a matter of staging the inserts such that only a certain amount of them could be written to the target db per second, and make that value configurable at run-time. Commented Sep 9, 2014 at 16:52
  • @user3062946 You are correct. It should be configurable. But not necessarily be at run-time. What I am looking for is a configuration at JDBC driver level to control the number of inserts flushed to database per second. Commented Sep 10, 2014 at 15:30
  • @Luiggi Mendoza I know that its odd, but this is our requirement because of some limitations in target database. Can you tell me how to do this? Commented Sep 10, 2014 at 15:32

1 Answer 1

1

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(); } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. Do you know is there any configuration available at JDBC driver level to control the number of inserts flushed to database per second.
I'm not aware if any JDBC driver implements this sort of thing. But alternatively you can pause your program to reduce load on the target server. This question explains well about batch insert.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.