Multithreading is a Java mechanism that allows concurrent execution of many block of a program for maximum utilization of CPU. Each block is called a thread. So, threads are light-weight processes within a process.

To create Threads we have two ways:
1. Extending the Thread class
2. Implementing the Runnable Interface

  1. Example of extending the Thread class :
class ThreadedSend extends Thread 
{ 
         ........
}

2. Example of implementing the Runnable Interface :

class ThreadedSend implements Runnable 
{ 
	.......
} 

The common question here is : Thread Class vs Runnable Interface , what is the difference ?

Tagged:

Laisser un commentaire