如何在Java中实现多个线程来下载单个表数据? [英] How to implement several threads in Java for downloading a single table data?

查看:71
本文介绍了如何在Java中实现多个线程来下载单个表数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现具有多个/相同连接的多个线程,以便可以快速下载单个大型表数据。

How can I implement several threads with multiple/same connection(s), so that a single large table data can be downloaded in quick time.

实际上在我的应用程序,我正在下载一个有12个lacs(1 lac = 100,000)记录的表,这个记录需要至少4小时才能以正常的连接速度下载,而更多的hrs连接速度慢。

Actually in my application, I am downloading a table having 12 lacs (1 lac = 100,000) records which takes atleast 4 hrs to download in normal connection speed and more hrs with slow connection.

因此,需要在Java中实现多个线程,以便下载具有多个/相同连接对象的单个表数据。但不知道如何做到这一点。

So there is a need to implement several threads in Java for downloading a single table data with multiple/same connection(s) object. But no idea how to do this.

如何在多个线程中定位记录指针然后如何将所有线程记录添加到单个大文件中?

How to position a record pointer in several threads then how to add all thread records into a single large file??

提前致谢

推荐答案

首先,不建议取得和将如此庞大的数据下载到客户端。如果您需要数据用于显示目的,那么您不需要更多适合您屏幕的记录。您可以对数据进行分页并一次获取一页。如果你正在提取它并在你的记忆中处理,那么你肯定会在你的客户端上耗尽内存。

First of all, is it not advisable to fetch and download such a huge data onto the client. If you need the data for display purposes then you dont need more records that fit into your screen. You can paginate the data and fetch one page at a time. If you are fetching it and processsing in your memory then you sure would run out of memory on your client.

如果你需要这样做,无论建议如何,然后你可以产生多个线程,这些线程具有到数据库的单独连接,其中每个线程将提取一小部分数据(1到多页)。如果您说100K记录和100个线程可用,则每个线程可以提取1K记录。同样不建议有100个线程与DB打开100个连接。这只是一个例子。将无数个线程限制为某个最佳值,并限制每个线程拉动的记录数。您可以根据rownum限制从DB中提取的记录数。

If at all you need to do this irrespective of the suggestion, then you can spawn multiple threads with separate connections to the database where each thread will pull a fraction of data (1 to many pages). If you have say 100K records and 100 threads available then each thread can pull 1K of records. It is again not advisable to have 100 threads with 100 open connections to the DB. This is just an example. Limit the no number of threads to some optimal value and also limit the number of records each thread is pulling. You can limit the number of records pulled from the DB on the basis of rownum.

这篇关于如何在Java中实现多个线程来下载单个表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆