Thursday, 23 May 2013

Threads In JAVA

Threads are lightweight compared to processes

The threads has a own lIfe cycle

Steps of Threads Life Cycle

1)init()
2)ready
3)start
4)wait/block
5)Destroy



Sysnta of creating threads


Threads t1=new Threads();


t1.start();


Basic Example




class Sample extends Thread {

 Sample()
{
 }
 Sample(String threadName) {
  super(threadName); // Initialize thread.
  System.out.println(this);
  start();
 }
 public void run() {
  
  System.out.println(Thread.currentThread().getName());
 }
}Aryantech pune



No comments:

Post a Comment