Java Concurrency Interview Question: Print N numbers via 2 threads one for each even and odd number

preview_player
Показать описание
In this video, we are going to discuss one of the most asked interview questions around threading. It is also very important from the understanding point of view. You will understand how to write threading based solutions.
Specifically, we are going to write a code in which we will be printing numbers from 1 to n with two threads. One thread will be printing the odd numbers and the other one will be printing the even numbers.

Thanks for watching. Hope you find this video helpful. Let me know the feedback in the comments.

Do subscribe to the channel!!

You can follow me on:
Рекомендации по теме
Комментарии
Автор

Just one request to all: If you do not like the video and are hitting unlike, then please put one comment so that I will know what made you do so. I will try to improve that in future videos :)
I just got 5 unlikes within 15 mins of launching the video :(. Is it really that bad? Please feel free to put your honest opinion in the comments :)

anomaly
Автор

My God, this way of solving the famous even odd problem using threads is simply the next level of thinking. Loved it ❤

randheer.chauhan.
Автор

I don't why few people dislike the vedio, someone is putting efforts and by disliking they are showing their capacity that they don't want to do anything in life, please if you don't like atleast don't dislike until the content is wrong

tanujagrawal
Автор

What you said in the beginning is true, even after 1year of posting this video; this is still a favorite question for the interviewers on multi threading.
Thanks for making this video

DiwakarShuklaALD
Автор

Hey udit big brother.
This video was beautifully put i completely understood I'm a fellow junior swe trying to be a sde2 or similar role i get stuck a lot like really struggle in lld. These videos are great please solve other questions as well. Your explanation is very proper

onepiece-hlhj
Автор

I just came here to LIKE the video.
We appreciate your efforts and value it too.
Keep it up, keep making content

Akash-okil
Автор

What if we use if instead of while for state.wait() call ?

akshayyelpale
Автор

Instead of explaining the final code, try to write code on live.
I mean start from beginning and build all functions step by step.
This will help viewers to understand how to think in correct direction.

Otherwise you are doing great work :)

shubhambansal
Автор

For completeness, lock on state variable is released in 'wait()' call and required when 'wait()' returns.

The follow up question would be to scale this solution for N threads where Thread_i will print i_th value. NotifyAll() is easy to use but is inefficient as it will wake all N-1 threads but only 1 will move forward and N-2 will go back to sleep.

AshishNegi
Автор

Oh god, udit sir you are awesome, loved the video :)

aishwaryadwani
Автор

Amazing as always! Please make more videos on multi-threading LLD/questions! Thanks for your efforts!!!

garimadhanania
Автор

one suggestion: please take some simple example, It was a bit boring. But end the end I got the concept. Thank you

chandankumar-sung
Автор

Thanks a lot bro, it not only thought me about the problem itself but also an idea about about how to write code to make it more reusable, I am a fresher to development and I didn't understand why you were using final keyword when you were creating those objects in main file.

adabaladurgaprasad
Автор

It really helped, but one suggestion if you could explain the code a bit more, say why did you used final...is this a best practice...but overall this is awesome, thanks for sharing your knowledge😇, I also faced a similar question where i have to find sum of elements upto n using threads concept

muskangupta
Автор

It's a highly informative video even all videos are informative. My little effort to keep you motivated is, I have pressed all videos with a like button. Hope it may help you to overcome the apathy that occurs due to dislike. :) stay safe.

saurabhkiet
Автор

Nice work Udit!! In few concepts though, I feel diagrams make more sense or rather easy to understand for viewers (like the part where you were explaining about curr & next state for thread), might be a good idea to include some diagrams or dry runs too. All things apart, you're doing great for the community & I hope you'll continue to do so. About the dislikes: no one in the world can satisfy everyone. You're doing great, keep it up & thanks for spreading your knowledge & experience. 🙌

siddharthgaur
Автор

Bhai masth informative video.
Keep up good work bhai.
Aaj kal achhi video daal rehe ho bhai :)

ankur
Автор

Thank you for this video! I'd like to request you to post more videos based on threading/concurrency in Java.

akshatbhardwaj
Автор

Great work Udit! It is providing clear insights on multithreading concept.

priyankamishra
Автор

Glad I found this channel. Instantly shared this video to my friends...
Sir, the way you explained is just lit 🔥 can't be explained in words sir.

Thank you sir, for such a great content ❤️

adityashidlyali
welcome to shbcf.ru