Either t1.join() or t2.join() is sufficient. The thread from which join is called (ie. the main thread in this example), will exclude itself from executing until the other threads complete and joins them at the end.
t1.Alive() and t2.Alive is called in the main thread, So the correct explanation is the main thread will wait for both t1 and t2 thread to complete its execution only after which it will print "bye".
Great Great Tutorial! Please can you Number/ Identify your videos sequentially. Like = "MULTI-THREADING PART 1" , "MULTI-THREADING PART 2", "MULTI-THREADING PART 3" and so on... So we can follow your lesson properly and not jump. THanks
A bit too late, but maybe someone else also asks this question. Not an expert but i think: t2.join() forces other work to wait for it completion. In this scenario: t1.start();t2.start();t2.join();otherWork(); -> t1 and t2 will be executed parallelly and otherWork() waits for t2. Scenario 2: t2.start();t2.join();t1.start();otherWork(); -> Both, t1 and otherWork(), will have to wait until t2 is finished.
think about it... if you are going to place the "bye"(main thread) in finally, you can either place it in the finally block of thread *t1* OR *t2* . Say u place it the finally block of *t1* . So if *t1* finishes its task then it will execute the "bye". it wont bother if *t2* have completed or not and it will print bye. incase the *t2* havent completed, then "bye" wont be printed at last, instead it will be printed in between. so to avoid this. its better to wait for both the threads to finish
I am from Bangladesh..Nothing to say..But you are awesome LEGEND...........
Either t1.join() or t2.join() is sufficient. The thread from which join is called (ie. the main thread in this example), will exclude itself from executing until the other threads complete and joins them at the end.
t1.Alive() and t2.Alive is called in the main thread,
So the correct explanation is the main thread will wait for both t1 and t2 thread to complete its execution only after which it will print "bye".
1:55 I can sense the stare :P
yaaaa
So the meaning of "join" is t1 and t2 will join back main thread after they finish their own thread. So main thread has to wait for their join.
sir i inspired on u very good tutorials i learned new day by day thank u ...
Awesome video!! I never understood till watching this :)
We r in ur support
Lovely explanation.
Great Great Tutorial!
Please can you Number/ Identify your videos sequentially. Like = "MULTI-THREADING PART 1" , "MULTI-THREADING PART 2", "MULTI-THREADING PART 3" and so on... So we can follow your lesson properly and not jump. THanks
Your accent is awesome!!!
I think only one join() either in Thread1 or Thread2 is enough to join other thread.
Correct me if I am wrong.
Hey very nice video. I'm big fan of you now. keep up the good work
can we get live java classes freely?
Like From Uzbekistan 🇺🇿🇺🇿🇺🇿🇺🇿🇺🇿🇺🇿
Please make a video on Atomic operations for Multithreading! Thanks
you can also use finally
Very helpful Thank You
Helli sir i have a problem in this example join and isalive method not working and not taking the output is same as example please answer
Same here if u sort out it please ping me
Hi Sir, here we have throws exception .but not handled with try catch.since it is runtime exception we can do so?
Please reply
Great explanation.
It does not work with THREAD CLASS by implementation of run method why ? I wrote same code using Thread class it is not executing why ??
You haven't written extend thread
Hey quick question, can you describe .join is this a blocking/non-blocking in regards to the UI thread? Great video thank you :)
This is an good video!
sir what will be happen if t1 is not called join but t2 is called join..
A bit too late, but maybe someone else also asks this question. Not an expert but i think: t2.join() forces other work to wait for it completion. In this scenario: t1.start();t2.start();t2.join();otherWork(); -> t1 and t2 will be executed parallelly and otherWork() waits for t2.
Scenario 2: t2.start();t2.join();t1.start();otherWork(); -> Both, t1 and otherWork(), will have to wait until t2 is finished.
why we are using throws exception with join()
And what kind of exception will be?
anikeat bansal it will be InterruptedException
What if we simply print Bye after ending the scope of thread
but the scope the threads here is the main methods itself?
Thread t1= new Thread(()->
Thread(()->
When we write "()->" whats this?
Is it same as -
new Thread(new Runnable(){
});
read about lamda expression
@@nabujjalnath8219 ok bro thanks
this is the concept of lambda expression
@@manikandand2541 woahh ok got it
Thankyou bro
instead of join(), why can't we use finally keyword there?
yeah even I thought same when I watched this video
think about it... if you are going to place the "bye"(main thread) in finally, you can either place it in the finally block of thread *t1* OR *t2* . Say u place it the finally block of *t1* . So if *t1* finishes its task then it will execute the "bye". it wont bother if *t2* have completed or not and it will print bye. incase the *t2* havent completed, then "bye" wont be printed at last, instead it will be printed in between. so to avoid this. its better to wait for both the threads to finish
nice video
if we write join for only one thread also its working, i mean bye is printing at the end only. t1.join();
Try to increase the for loop of t2 or you can decrease sleep time of t1... Try out....
Why it is happening?? With only t1. join()
1:56 some kids voice :)
@Telukso
❤
won't u read comments bud!!