在并行读取数据 [英] fetching data in parallel

查看:187
本文介绍了在并行读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,我想从多个社交媒体数据(家庭时间表)集成了一个Android应用程序。进行API调用,并且从每个人得到的响应是位的时间,如果以串行方式进行耗时。所以,我希望有一个并行环境,使API调用影的Instagram等,并在最短的时间获取数据。

I am developing an android application in which I want to integrate data(home timeline) from multiple social medias. Making API calls and getting response from each of them is bit time consuming if done in a serial fashion. So i want a parallel environment to make API calls to facebook twitter Instagram etc. and fetch the data in minimum time.

我已经使用异步任务在present从每个社会media..i.e 1异步任务获取的数据将调用了Facebook的API来获取数据,第二个将调用的Twitter的API等。我把从UI线程异步的所有任务。我认为所有的异步任务将在并行环境中同时工作。但在运行code后,似乎别人的一个异步任务块的工作,他们被调用只以串行方式。所谓第一异步任务首先完成的工作和被称为最后的AsyncTask在去年完成的工作。我使用开发Android版本为4.3。我已搜查约线程池EXECUTOR android系统中进行并行处理,但我没有得到一个明确的概念。这将是巨大的,如果有人能帮助我。提前致谢。

I have used Async tasks at present for fetching data from each social media..i.e one async task will call the api of facebook for fetching data, second will call the api of twitter and so on. I call all the async tasks from UI thread. I thought that all async tasks will work simultaneously in a parallel environment.. But after running the code it seems that one async task blocks the work of others and they get called only in a serial fashion. First async task called completes the work first and the last asynctask called completes the work at last. Android version I am using for development is 4.3. I have searched about THREAD POOL EXECUTOR in android for parallel processing but i am not getting a clear idea. It would be great if anyone can help me out. Thanks in advance.

推荐答案

不同版本的Andr​​oid处理AsyncTasks不同的。之前1.6,任务进行系列处理。从1.6到2.3.7它们与一个线程池异步处理。从3.0就回串行处理它们。

Different versions of Android handle AsyncTasks differently. Prior to 1.6, tasks were handled serially. From 1.6 to 2.3.7 they were handled asynchronously with a thread pool. From 3.0 on they went back to handling them serially.

您可以通过显式指定执行者强制使用一个线程池。

You can force the use of a thread pool by explicitly specifying the executer.

而是调用下面来执行你的任务

Instead of calling the following to execute your tasks

task.execute(param1, param2, ...)

呼叫

task.executeOnExecuter(AsyncTask.THREAD_POOL_EXECUTER, param1, param2, ...)

这篇关于在并行读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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