0% found this document useful (0 votes)
2 views2 pages

5 1 0 Intoduction MultiThreading

Multithreading in Java allows for the concurrent execution of multiple threads, improving system responsiveness and resource utilization. A thread is a lightweight sub-process, and using the java.lang.Thread class is essential for creating multithreaded applications. Benefits include higher throughput, responsive applications, and efficient resource use, as demonstrated in an example with separate threads for even and odd number processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

5 1 0 Intoduction MultiThreading

Multithreading in Java allows for the concurrent execution of multiple threads, improving system responsiveness and resource utilization. A thread is a lightweight sub-process, and using the java.lang.Thread class is essential for creating multithreaded applications. Benefits include higher throughput, responsive applications, and efficient resource use, as demonstrated in an example with separate threads for even and odd number processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Multi Threading

Multithreading enables us to run multiple threads concurrently.

Multithreading in Java is a process of executing multiple threads simultaneously.

To achieve the multithreading (or, write multithreaded code),


you need java.lang.Thread class.
what is thread
A thread is a lightweight sub-process, the smallest unit of processing.

For example

In a web browser, we can have one thread which handles the user interface, and in parallel we
can have another thread which fetches the data to be displayed.
So multithreading improves the responsiveness of a system.

Benefits of multithreading
1. Higher throughput, or the ability to process more units of information in a given amount of time.
(This assumes that the throughput ‘cost’ associated with dealing with multiple threads is lower
than the efficiency it creates. This is usually, but not always, the case.)
2. More responsive applications that provide user seamless experiences and the illusion of
multitasking. For example, an app’s UI will still be functional and responsive even while IO activity
is happening in the background of an image processing app.
3. More efficient utilization of resources. Generally speaking, thread creation is less ‘costly’
compared to creating a brand new process. Web servers that use threads instead of creating a
new process when fielding web requests consume far fewer resources.

MultiTheading
1.Thread 1: Even No
2.Thread 2: Odd No
class even extends Thread Output:
{
public void run() even number:2
{ odd number3
for(int i=0;i<10;i+=2) even number:4
System.out.println("even number:"+i); odd number5
} odd number7
} even number:6
odd number9
class odd extends Thread even number:8
{
public void run()
{
for(int i=1;i<10;i+=2)
System.out.println("odd number" +i);
}
}
class EvenoddThread4
{
public static void main(String arg[])
{
even e=new even();
odd o=new odd();
e.start();
o.start();
}
}

You might also like