I used Runnable interface. I still have my code, back when I was working with jdk.1.4. Main reason I used Runnable is to avoid calling thread's stop() method, which is not advisable back then
I think the above results are based on your Runnable-instance threads implementation. For example, if you create: ImplementsRunnable r1 = new ImplementsRunnable(); Thread t1 = new Thread(r1); t1.start(); ImplementsRunnable r2 = new ImplementsRunnable(); Thread t2 = new Thread(r2); t2.start(); ImplementsRunnable r3 = new ImplementsRunnable(); Thread t3 = new Thread(r3); t3.start(); instead of "Thread t1 = = Thread t2 = Thread t3 = new Thread(r)", all created from the same Runnable instance, the results from both will be the same counter = 1/1/1.
hi, if we miss Thread.sleep(1000) method .. Runnable interface counter showing all count as same.. 3 times counter called.. all will be 3. not like 1,2,3. why it's shwoing if miss sleep() why same value printing. Thanks Rajesh
Thank you so much for the video,
I have understood the differences between runnable and the use of threads....
I used Runnable interface. I still have my code, back when I was working with jdk.1.4. Main reason I used Runnable is to avoid calling thread's stop() method, which is not advisable back then
I think the above results are based on your Runnable-instance threads implementation. For example, if you create:
ImplementsRunnable r1 = new ImplementsRunnable();
Thread t1 = new Thread(r1);
t1.start();
ImplementsRunnable r2 = new ImplementsRunnable();
Thread t2 = new Thread(r2);
t2.start();
ImplementsRunnable r3 = new ImplementsRunnable();
Thread t3 = new Thread(r3);
t3.start();
instead of "Thread t1 = = Thread t2 = Thread t3 = new Thread(r)", all created from the same Runnable instance, the results from both will be the same counter = 1/1/1.
Thank you so much....
Interesting, I didn't know it 🤔
hi,
if we miss Thread.sleep(1000) method .. Runnable interface counter showing all count as same.. 3 times counter called.. all will be 3.
not like 1,2,3. why it's shwoing if miss sleep() why same value printing.
Thanks
Rajesh
Very precise and lucid explanation
Thank you Abhishek !!