5 1 0 Intoduction MultiThreading
5 1 0 Intoduction MultiThreading
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();
}
}