0% found this document useful (0 votes)
11 views4 pages

Threading Models and Their Role in Enhancing Performance

Uploaded by

nmmalantawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Threading Models and Their Role in Enhancing Performance

Uploaded by

nmmalantawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Republic of the Philippines

UNIVERSITY OF SOUTHERN MINDANAO


Kabacan, Cotabato

COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY

CS 10 - Operating Systems
1st Semester 2024-2025

Title: Assignment 2
Topic: Threading in Operating Systems
Name of Student:
Date Accomplished:

Threading Model in Android OS

Overview
Android OS, which is based on the Linux kernel, primarily uses kernel-level threads. These
threads are managed by the Linux kernel, providing support for true parallelism on multi-core
processors, and allowing threads to be scheduled independently by the operating system.
Android applications typically rely on Java-based threading but ultimately run as kernel-level
threads, allowing efficient management of CPU resources.

Kernel-Level Threads

In Android, threads created by applications are kernel-level threads. This means that
the operating system directly handles their execution and scheduling, rather than the
application itself managing them. Kernel-level threading allows Android to leverage the
underlying Linux kernel’s capabilities, enabling efficient multitasking and concurrency,
particularly on devices with multi-core processors.

Key Functions and APIs for thread Management in Android

Android provides several threading mechanisms and APIs tailored to its environment, each suited for
different purposes:

 Java Thread API


The fundamental threading approach in Android is through the thread class, which allows
developers to create threads by extending thread or implementing the runnable interface. This
is often used for basic threading operations, such as executing a task in the background without
blocking the main UI thread.
 AsyncTask

The AsyncTask class was a popular way to perform background operations and update
the UI in Android. It simplified background tasks, particularly when short-lived opera-
tions were needed. However, due to limitations with lifecycle management and perfor-
mance, AsyncTask has been deprecated in favor of alternatives like Executors and Work-
Manager.

Handler and Looper

Handlers and Looopers are integral to Android’s threading model. A looper prepares a
thread to run a message queue, enabling it to handle asynchronous tasks. The main UI
thread has a looper by default, which makes it responsive to user input. Handler objects
allow thread to send and process messages and runnable objects, enabling task to run
specific threads without directly creating new ones.

Executors

Executor is a high-level API between Thread and AsyncTask that can manage thread
pools to limit the number of concurrent threads. Executors provide pre-configured
thread pools, which are useful for executing time-controlled tasks. If we create a thread
for every task, it can overwhelm the CPU with threads.

applications with rich graphical content often require that complex tasks be computed within a time
limit. The limitation on the response time can often be achieved by performing some of the processing
duties on other cores of the device. This is because devices nowadays come with multi-core processors
that enable multi-threading and these applications support multi-threading. For instance, if two players
are playing a game of chess with a reasonable time limit, then to help with the computation of the next
move, each player’s device would process the chess board image using the available cores, thus
speeding up the process of making the next move.

• Improving Performance with Background Workers


Some tasks within some applications may take long time
to execute normally, that is why performing them in the
very first the application’s life cycle or in the process of
interaction with the user becomes impossible. Instead of
attempting to execute such long-running operations on
the main UI thread or the only working thread,
background services can be relied upon to perform duties
like downloading or uploading huge files that may
otherwise hinder the progress of other
WorkManager
WorkManager is an API designed to handle long-running
background tasks with built-in lifecycle management. It is
especially useful for tasks that need to run even if the
app is closed or the device restarts. WorkManager is ideal
for operations like background data syncing, which may
not require immediate execution but must persist
through app closures or device reboots.

Benefits of Threading in Android OS

Threading significantly enhances performance and responsiveness in Android applications, espe-


cially in resource-intensive or interactive applications. Here are some examples of how threading
improves the Android user experience:

 Improving Responsiveness in UI-Driven Applications


Applications that perform tasks like image processing, network requests, or database op-
erations leverage background threads to avoid blocking the main UI thread. This ensures
that the app remains responsive to user interactions, providing a smoother and more en-
joyable user experience. For instance, a messaging app would use background threads to
handle tasks such as fetching new messages from a server without freezing the UI.
 Efficient Resource Utilization in Background Processing
Apps that require ongoing background work, like downloading large files, updating data,
or synchronizing with cloud services, benefit from using Executors and WorkManager.
These APIs manage resource allocation by limiting the number of concurrent threads, en-
suring that tasks don’t overwhelm the device’s CPU or memory. For example, a news app
might use background threads to fetch the latest articles and store them locally, allowing
users to read them offline while ensuring minimal impact on system resources.
 Parallelizing Computation-Intensive Tasks
Games and graphical applications often use multiple threads to manage complex tasks
like rendering graphics, handling user input, and playing audio simultaneously. By sepa-
rating these tasks into different threads, Android can process them in parallel, taking ad-
vantage of multi-core processors and providing a seamless and high-performance gaming
experience.

Android’s threading model is highly versatile, enabling developers to build responsive, efficient,
and resource-friendly applications. By offering multiple APIs tailored to different use cases, An-
droid provides the tools necessary to manage background and foreground tasks in a way that en-
hances both application performance and user satisfaction.

You might also like