my Android app extends a number of Thread and AsyncTask Classes. I used either of these classes when loading an Activity. I am doing this to run an I/O task and show a dialog to the user if the load time is more then a second. It would be safe to say that there will be only one thread or AsynTask running at a time (not including the main UI). Do I need 开发者_如何学Pythona thread Pool?
No it would not at all safe to assume that. In all probability there would be multiple threads running (although on a single core) - what you should be bothered about is what you can really control - make sure your user does not have a bad experience - I think you are doing that already by keeping a separate thread for the UI.
In fact it is very much possible to run multiple threads (more than 2 excluding the UI thread) from the same activity itself by using the AsyncTask. Android itself has many threads running and it has certain priorities which need to be honored as well. If we break the priority by writing a our own Thread Pool (I'm doubtful if we will have access to all the threads on non-jail broken phones) the system might become unstable and might lead to frequent crashes.
Android has an inbuilt algorithm to call the garbage collector and also to kill threads in case they are greedy / starving other threads to death. So while designing a good application, we also need to cover such corner cases otherwise we end up with lots of NPEs at the service.start() and that too pretty randomly.
Also, from the latest phones, it looks like newer phones with dual cores have already come out :)
精彩评论