commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Xiaodan Zhou (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DBUTILS-83) Add "BatchUploader" (related to DBUTILS-78 but different)
Date Tue, 28 Oct 2014 19:17:34 GMT

    [ https://issues.apache.org/jira/browse/DBUTILS-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14187319#comment-14187319
] 

Daniel Xiaodan Zhou commented on DBUTILS-83:
--------------------------------------------

Clean up the file and rename it to "AsyncQueueProcessor".

> 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)

Mime
View raw message