Add "BatchUploader" (related to DBUTILS-78 but different)
---------------------------------------------------------

                 Key: DBUTILS-83
                 URL: https://issues.apache.org/jira/browse/DBUTILS-83
             Project: Commons DbUtils
          Issue Type: New Feature
    Affects Versions: Nightly Builds
            Reporter: Daniel Xiaodan Zhou
            Priority: Minor


I have created a BatchUploader class in one of my project, and thought I might 
contribute it to DbUtils.

It is similar to DBUTILS-78, but is different. It is basically a 
"producer-consumer" queue, where you application produce rows, and 
BatchUploader "consumes" the rows and write them back to the database. 
DBUTILS-78 also uses multi-threading, but it doesn't have the 
"producer-consumer" queue. So you could imagine cases where you add too many 
rows in a batch before run executeBatch() and cause "Java Out of Memory". Also, 
BatchUploader only uses simple Thread class, so it's more compatible to other 
Java libraries compared to using ExecutorService/Future.

Here's how you use BatchUploader in you application:

uploader = new BatchUploader(threadName, dbConnection, sqlStmt);
uploader.start();
while (...) {
  uploader.put(...); //  here you put each row in the queue
}
uploader.accomplish();
// some other code ...
uploader.join(); // wait the uploader to finish before moving to the rest of 
the code.
// continue running ...


The code attached is directly copied from my project. If people here think it 
should go into DbUtils, I can add more javadoc and remove the specific things 
that were used in my project to make it more general.


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to