13.3 Multithreading using Runnable Interface

13.3 Multithreading using Runnable Interface

Telusko

7 лет назад

304,262 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Srushti Hirve
Srushti Hirve - 19.11.2022 12:12

Can anyone explain this code to me please!!!

class myThread implements Runnable{
Thread t;
myThread(){
//creates a my thread
t = new Thread(this , "Demo thread");
System.out.println("child thread : " +t);
}
//this is the entry point for 2nd thread
public void run(){
try{
for(int i=5 ;i>0 ; i--){
System.out.println("child thread : " +i);
Thread.sleep(500);
}
}catch(InterruptedException e){
System.out.println("child interrupted ");
}
System.out.println("exiting child thread ");
}
}

class ThreadDemo{
public static void main(String args[]){
myThread nt= new myThread();
nt.t.start();
try{
for(int i=5 ;i>0 ; i--){
System.out.println("MAIN thread : " +i);
Thread.sleep(1000);
}
}catch(InterruptedException e){
System.out.println("main thread interrupted ");
}
System.out.println("exiting main thread ");
}
}

Ответить
Wsha Code
Wsha Code - 25.10.2022 17:39

so help full really

Ответить
Decoding My Roots
Decoding My Roots - 24.12.2021 13:56

Thanks

Ответить
Kahan
Kahan - 28.11.2021 20:56

I'm watching this after 5 years and it still helped me a lot!

Ответить
Vinothini A
Vinothini A - 08.08.2021 06:02

Please make a video on completable future

Ответить
Manan Chawla
Manan Chawla - 15.04.2021 14:00

how is runnable interface linked to Thread class ?

Ответить
Patteboyina Dharani
Patteboyina Dharani - 14.03.2021 13:09

No words to describe about your teaching sir......... 👏👏👏👏👏👏👏

Ответить
Sengottaiyan Periyasamy
Sengottaiyan Periyasamy - 10.12.2020 17:23

Hi, how can we implement thread in spring projects , please provide the exact real time scenario. Thanks

Ответить
Darshan Gaikwad
Darshan Gaikwad - 14.10.2020 19:42

when i use start method it shows error but when i use run in it shows coorect ouput please answer me why this occurs

Ответить
Muhammad Bilal Malik
Muhammad Bilal Malik - 30.08.2020 13:08

Perfect Telusko Binod!!!!

Ответить
Bouhenni Ouahiba
Bouhenni Ouahiba - 06.08.2020 22:42

hello,
how I do the synchronization with algorithm between multiple clients

Ответить
abdulashique
abdulashique - 12.07.2020 17:54

It will also work the same, even if you create objects of the Class itself and not Runnable interface
FirstThread firstThread = new FirstThread();
SecondThread secondThread = new SecondThread();
Thread t1 = new Thread(firstThread);
Thread t2 = new Thread(secondThread);
t1.start();
Thread.sleep(10);
t2.start();

Ответить
ronny pro
ronny pro - 10.04.2020 02:37

thanks.. so helpful

Ответить
Manan Desai
Manan Desai - 11.09.2019 14:30

Very easy to understand java when you teach us sir .....

Ответить
Hassaan Ahmad
Hassaan Ahmad - 04.08.2019 21:51

Sir you have made me conquer java in no time.....for(int x=1;x<=infinity;x++){System.out.println"Respect and Love"}

Ответить
N63B44TÜ
N63B44TÜ - 24.07.2019 13:36

you are explaining very well, thx. I would say your videos are so good like the ones by thenewboston except you dont objectify your exs LOL

Ответить
Vijay K Yadav vantela
Vijay K Yadav vantela - 05.07.2019 20:47

Hi Naveen Reddy garu,
Please make a video on complete collections.
U have so much knowledge in java and superb explanation.Every one will understand your videos.

Ответить