Performance Comparison: AsyncTasks vs Threads

In my application, I have to call a method that does some hard work (I can feel the device is lagging). To avoid this, I created AsyncTask, and it works great.

I have implemented the same thing using Thread, and here it also does not give any hiccups and works great.

Now my question is which of the best in performance - AsyncTaskor Thread.

I know that AsyncTaskthreadpool uses to perform background tasks, but in my case it will only be called once. Therefore, I do not think that this will create problems.

Maybe someone sheds light on him. Which one should be used to increase productivity?

Note. Both are called in my operation, for example. from the UI stream.

+5
source share
3 answers

Maybe someone sheds light on him. Which should I use to improve performance?

I think if you imagine the case when you start with the native Thread and AsyncTask, I think that the performance will not be different.

Usually, native threads are used in case you do not want to inform potential potential USERprogress information in any task using UI. Here, native threads fail because they do not synchronize with the stream UI, and you cannot manipulate the user interface.

, AsyncTask , , , .

, - 5 , USER,

"- , , "

, -, - ( MB , "" ..), (, - "" ).

, asnwer:

?

, , , , . , . , ( 50 , , AsyncTask). .

:

, , API, java.util.concurrent (ThreadPoolExecutor, FutureTask ..)

+4

. , , . . , , .

, Async , Async , onPreExecute(), doInBackground(), onProgressUpdate() onPostExecute(), , (, ). . , Async - . , , , Async , Context .., .

.

:

  • . , .
  • : Async-, / . , .
+2

Thread - , .
AsyncTasks - - .

, AsyncTasks , .

-1
source

All Articles