You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Daniel Xiaodan Zhou (JIRA)" <ji...@apache.org> on 2014/10/28 20:17:34 UTC

[jira] [Updated] (DBUTILS-83) Add "BatchUploader" (related to DBUTILS-78 but different)

     [ https://issues.apache.org/jira/browse/DBUTILS-83?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Xiaodan Zhou updated DBUTILS-83:
---------------------------------------
    Attachment: AsyncQueueProcessor.java

> 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
>         Attachments: AsyncQueueProcessor.java, BatchUploader.java
>
>
> 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 was sent by Atlassian JIRA
(v6.3.4#6332)