Your SlideShare is downloading. ×
0
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Ts   threading
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Ts threading

166

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
166
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Boutique product development companyIt is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  • 2. ThreadingMuhammad Mateen| Android Mentor
  • 3. ThreadingTopics covered in the presentation • UI Thread • Loppers & Handlers • Async Tasks • Intent Services • Executor • Executor Service • Callables & Futures Muhammad Mateen| Android Mentor
  • 4. ThreadingUI Thread • When an application is launched, the System creates a Thread of execution called the Main Thread or the UI Thread. • Called the UI Thread because it is this thread which interacts with the UI widgets. • Don’t execute tasks that take more then 5 seconds? Why ? Muhammad Mateen| Android Mentor
  • 5. ThreadingUI Thread •Things to remember • No long operations • Don’t interact other threads with UI thread •The UI thread runs as a NORMAL PRIORITY thread. Muhammad Mateen| Android Mentor
  • 6. ThreadingUI Thread •UI Thread acts as a Pipeline Thread, similar to those from Swing or any other UI Framework •Each action is feed into a Pipeline, and processed •Any long operation can starve other tasks in the queue •We can use HANDLERS to interact with this queue Muhammad Mateen| Android Mentor
  • 7. ThreadingLoopers and Handlers •Ordinary thread to Pipeline thread •Loopers implements the loop •Handler feeds the task into Queue associated with the Thread •Together, multi-threaded processes can be handled •Handlers detect the Looper, implicitly •Each Handler is always tied to one Looper Muhammad Mateen| Android Mentor
  • 8. ThreadingAsync Tasks •Easiest way to offload onto a separate thread. • Executes task off the UI thread and post result on UI • Not used for long processes (why ? ) • Works parallel (for less 4.x) • Tied with Activity • On memory shortage, it likely to be killed Muhammad Mateen| Android Mentor
  • 9. ThreadingAsync Tasks • Why should be take care of point 3 ? • Well for one the API documentation says so • Secondly the Resource Queue is created by the System • Avoid straining resources that you did not allocate Muhammad Mateen| Android Mentor
  • 10. ThreadingAsync Tasks Methods • onPreExecute() • doInBackground() • onProgressUpdate() • onPostExecute() Muhammad Mateen| Android Mentor
  • 11. ThreadingIntent Service • Subclass of Service Class • Work Queue Process • Runs off the UI Thread • Can place long process in onHandleIntent() • Manages Worker Thread itself. • Can get a out-of-the-box-queue • Broadcast intents Muhammad Mateen| Android Mentor
  • 12. ThreadingExecutor • Pool of runnable tasks • Decouples the mechanics of a Task Submission from the process of how they will be executed. •We use this instead of creating Threads separately. Muhammad Mateen| Android Mentor
  • 13. ThreadingExecutor Service • Add lifecycle methods to Executor • Create N number of thread pool • Or Executors.newSingleThreadExecutor() for a Single runnable pool • shut down a executor will reject new Tasks Muhammad Mateen| Android Mentor
  • 14. ThreadingExecutor Service•Methods shutDown() – don’t kill the running tasks shutDownNow() – kill the running tasks• Unused ExecutorService can be shutdown, to claim for itsresources•Upon termination, an executor has no tasks actively executing,no tasks awaiting execution, and no new tasks can be submitted Muhammad Mateen| Android Mentor
  • 15. ThreadingCallables And Futures•Biggest Issue with Runnable ?•Callable return values after completion• Submitting callable to executor returns a Future• Futures can be used to check Callable’s status•Use the get method to retrieve the result of a Future Muhammad Mateen| Android Mentor

×