How to start new thread? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How to start new thread?

9th Mar 2016, 4:45 PM
Ranveer mourya
Ranveer mourya - avatar
3 ответов
+ 1
implement runnable extend thread class
5th May 2016, 2:19 PM
Alexona Kinuthia
Alexona Kinuthia - avatar
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(); } }
2nd Sep 2016, 4:47 AM
Sandeep Yohans
Sandeep Yohans - avatar
0
thank you so much ;)
20th Aug 2018, 1:08 PM
Ranveer mourya
Ranveer mourya - avatar