0
How to start new thread?
3 ответов
+ 1
implement runnable
extend thread class
0
Try running this code, here I have created and started 4 threads namely Thread0, 1, 2 and 3.
Each time u run this program the output will be different. This happens because of the thread execution by processor, the magic of multithreading!
class MyThread0 extends Thread {
public void run() {
System.out.println("Hello, I'm MyTHread 0");
}
}
class MyThread1 extends Thread {
public void run() {
System.out.println("Hello, I'm MyTHread 1");
}
}
class MyThread2 extends Thread {
public void run() {
System.out.println("Hello, I'm MyTHread 2");
}
}
class MyThread3 extends Thread {
public void run() {
System.out.println("Hello, I'm MyTHread 3");
}
}
public class MyClass {
public static void main(String[ ] args) {
MyThread0 zero = new MyThread0();
MyThread1 one = new MyThread1();
MyThread2 two = new MyThread2();
MyThread3 three = new MyThread3();
zero.start();
one.start();
two.start();
three.start();
}
}
0
thank you so much ;)