Friday, May 25, 2012

what happens if u start a thread more than one time


package com.yagapp.phaseone;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Duplicate_List extends Thread{

/**
* @param args
*/
public void run(){

System.out.println("ramesh");
}

public static void main(String[] args) {

Duplicate_List t = new Duplicate_List();
t.start();
t.start();
t.start();
t.start();
t.start();
t.start();

}

}


this will give u run time exception according to the documentation of the Thread . start () methode

      1) It is never legal to start a thread more than once.
      2) In particular, a thread may not be restarted once it has completed execution.

No comments:

Post a Comment