JAVA Multithreading Tutorial.

First of question comes in mind what is multithreading ?

Answer to this is ,Multithreading is a specialized form of multiprocessing .This uses a concept of multiple threads these thread can one,two or more.This enables the computer to utilizes its idle CPU time .This is one the most important advantages of multithreading .When one thread is waiting for input or output then mean while the other thread can perform other task this reduces the idle time of the CPU.



Multithreading help us to write intelligence programming that use most of CPU cycle.The idle time of the CPU is kept minimum.This is very useful for creating interactive programmes through JAVA .

Example :   Suppose you are programme is waiting for the input in same while the programme is displaying other messages or computing some problems . This fuctionality make our programmes interactive .

Thread can created in programme in two ways.
=> By implementing Runnable interface
=>By extending Thread class.

However we can if want to override some method of thread class then we can use extend method if not then we can use implementing method .


Implementing Runnable

we can construct the Thrad of any object that implements Runnable, a class need only a single method called run(). which is declared like this.


public void run().



Extending a Thread.

This is second waay of creating the thread .In this method you have to inherit the Thread class extending the class.and just override the run() method.

No comments:

Post a Comment