Java Threads Implements Runnable Example Program

By | December 25, 2010
You can get Java code for Threads class implements runnable program. You can get the example program for Java Threads Implements Runnable.

You can get Java code for Threads class implements runnable program. You can get the example program for Java Threads Implements Runnable.

class PrintNameRunnable implements Runnable {
public PrintNameRunnable(){
System.out.println(“New Thread started”);
}
public void run() {
for (int i = 0; i < 50; i++) {
System.out.print(i+”  “);
}
}
}
public class ImplementRunnable1 {
public static void main(String args[]) {
PrintNameRunnable pnt1 = new PrintNameRunnable ();
Thread t1 = new Thread(pnt1);
t1.start();
PrintNameRunnable pnt2 = new PrintNameRunnable ();
Thread t2 = new Thread(pnt2);
t2.start();
}
}
Result:
New Thread started
New Thread started
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 *