Android的线程与单核 [英] Android Threading with single core

查看:209
本文介绍了Android的线程与单核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道,如果有一个处理器线程提高的东西给我。
我建立一个用户界面运行时(在PCM数据FFT)执行数据密集型计算,需要平稳运行的应用程序。

Just wondering if threading with one processor improves things for me. I am building an application that performs data intensive calculations (fft on pcm data) while a UI is running and needs to run smoothly.

我一直在寻找的AsyncTask,但想法是:

I have been looking at AsyncTask but was thinking:

如果我有一个单核处理器(600 MHz的ARM处理器11)运行在我的Optimus One,将穿线有所作为?我想了线程运行independantly你需要多个处理器?还是我错了地方?

If I have a single core processor (600 MHz ARM 11 processor) running on my Optimus One, will threading make a difference? I thought for threads to run independantly you would need multiple processors? Or have I gone wrong somewhere?

推荐答案

为了保证响应速度,当务之急是要离开主或UI线程做UI的事情。这不包括在游戏中密集的图纸或3D渲染。当你开始做计算密集型的事情在你的主线程,用户将看到的滞后。一个典型的例子:

In order to guarantee responsiveness, it is imperative to leave the main or UI thread to do the UI things. This excludes intensive drawing or 3d rendering in games. When you start to do computationally intensive things in your main thread, the user will see lag. A classic example:

点击一个按钮,睡眠(1000)。与此对比,点击一个按钮,启动了睡觉的AsyncTask(1000)。

on a button click, sleep(1000). Compare this with, on a button click, start an AsyncTask that sleeps(1000).

这是AsyncTask的(和其他线程)允许应用程序来处理计算和UI交互simulataneously。

An asynctask (and other threading) allows the app to process the calculations and UI interactions "simulataneously".

至于并发性是如何工作的,上下文切换是游戏的名字(丹员额)。

As far as how concurrency works, context switching is the name of the game (as Dan posts).

在多线程的单核CPU不会增加你的表现。事实上,与上下文切换有关的开销将实际上会降低你的表现。但是,谁在乎你的应用程序是如何快速工作,当用户获取与UI沮丧,只是关闭应用程序?

Multithreading on a single core cpu will not increase your performance. In fact, the overhead associated with the context switching will actually decrease your performance. HOWEVER, who cares how fast your app is working, when the user gets frustrated with the UI and just closes the app?

AsyncTask的是去,肯定了道路。

Asynctask is the way to go, for sure.

这篇关于Android的线程与单核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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