Java Thread Sample Program by using Extend Thread

By | December 25, 2010
You can get Java code for sample thread program by using the extend thread concept in Java.
You can get Java code for sample thread program by using the extend thread concept in Java.
class PrintThread extends Thread{
String name;
public PrintThread(String msg){;
name = msg;
System.out.println(“Thread: “+ name);
start();
}
public void run(){
for (int i = 0; i < 50; i++) {
System.out.print(i+”  “);
}
}
}
public class ExtendThread2 {
public static void main(String[] args) {
new PrintThread (“Thread1”);
new PrintThread (“Thread2”);
}
}
Result:
Thread: Thread1
Thread: Thread2
0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49

Leave a Reply

Your email address will not be published. Required fields are marked *