Java的:TaskExecutor的异步数据库写入? [英] Java: TaskExecutor for Asynchronous Database Writes?
问题描述
我想使用Java的TaskExecutor接口来火了异步数据库写入的。可以理解的是线程不来免费的,但假设我使用的5-10说一个固定的线程池大小,这是怎么个坏主意?
I'm thinking of using Java's TaskExecutor to fire off asynchronous database writes. Understandably threads don't come for free, but assuming I'm using a fixed threadpool size of say 5-10, how is this a bad idea?
我们的应用程序中使用的缓冲液从一个非常大的文件的读取和执行某些数据操纵后刷新该信息给数据库。使用异步写入似乎理想在这里,以便我们能够继续对文件的工作。我在想什么?为什么不是每个应用程序中使用异步写入?
Our application reads from a very large file using a buffer and flushes this information to a database after performing some data manipulation. Using asynchronous writes seems ideal here so that we can continue working on the file. What am I missing? Why doesn't every application use asynchronous writes?
推荐答案
想法是不坏的。其实我昨天刚试了一下,因为我需要创造有5不同类别像60000项在线数据库的副本每个。
Idea is not bad at all. Actually I just tried it yesterday because I needed to create a copy of online database which has 5 different categories with like 60000 items each.
通过移动解析/保存每个类别的操作进入并行任务和分区每个类别导入到较小的批次并行运行我减少了进口总额的时间从几个小时(估计)至26分钟。一路上,我发现好片code的分裂集合:的http:// www.vogella.de/articles/JavaAlgorithmsPartitionCollection/article.html
By moving parse/save operation of each category into the parallel tasks and partitioning each category import into smaller batches run in parallel I reduced the total import time from several hours (estimated) to 26 minutes. Along the way I found good piece of code for splitting the collection: http://www.vogella.de/articles/JavaAlgorithmsPartitionCollection/article.html
我用ThreadPoolTaskExecutor类运行的任务。你的任务只是简单实现Callable接口的。
I used ThreadPoolTaskExecutor to run tasks. Your tasks are just simple implementation of Callable interface.
这篇关于Java的:TaskExecutor的异步数据库写入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!