Using volatile vs AtomicInteger in Java concurrency
ฝัง
- เผยแพร่เมื่อ 5 ก.ย. 2024
- When to use volatile, and when to use Atomic counterparts like AtomicInteger? What are the advantages and use cases of each?
Channel
----------------------------------
Complex concepts explained in short & simple manner. Topics include Java Concurrency, Spring Boot, Microservices, Distributed Systems etc. Feel free to ask any doubts in the comments. Also happy to take requests for new videos.
Subscribe or explore the channel - / defogtech
New video added every weekend.
Popular Videos
----------------------------------
What is an API Gateway - • What is an API Gateway?
Executor Service - • Java ExecutorService -...
Introduction to CompletableFuture - • Introduction to Comple...
Java Memory Model in 10 minutes - • Java Memory Model in 1...
Volatile vs Atomic - • Using volatile vs Atom...
What is Spring Webflux - • What is Spring Webflux...
Java Concurrency Interview question - • Java Concurrency Inter...
Not saying for the sake of saying but after visiting a lot of other channels I always come back to your videos for anything related to multithreading. You are simply awesome.
Hey man. I know this is already a 2year old video but I would like to express my thanks for putting these videos and I really learned a lot. Anything related to threads and concurrency in Java have been very intimidating for me and I always thought it's not important as I'm doing well in my current role in the company I'm working with. However, I realized my career as a software engineer is in rot due to not taking risks and for not taking on challenges by exploring what is out there for me.
I applied for Canva(spoiler: didn't got the job) and since then, I started watching your videos and practice coding related to java concurrency because it was advised on their role description. I'm still brokenhearted by the feedback that I didn't pass their first coding exam, hence, was not able to apply what I've learned from you. I'm still very thankful for what I've learned from your videos and made me more interested in this part of java.
Keep on making videos. Thanks!
+1 prepping for Canva here. Coincidentally found this video and this comment.
"The Best Content" for concurrency in java. Thanks much!
Done thanks
0:40 changing a variable in one thread will NOT reflect in the other thread. (Threads both have access to the variable, but each thread running on a different core the cpu has a local cache of the variable)
2:30 volatile solves visibility issue but doesn’t solve synchronization issues (when both threads are modifying the same variable, both could increment but the value is only +1 instead of +2)
4:50 solving synchronization with synchronized keyword
5:15 atomic variables provide atomic operations (incrementong happens as one operation instead of read then increment then write, where both threads could be running together)
6:30 which variables to make volatile and which values to make atomic
Probably the most comprehensive explanation I've seen yet (recommend listening at 1.5x), thanks alot!
After reading hundreds of resources finally I got the answer her. How to and where to use Volatile and Atomic variables.
Clear and precise explanation...Best Ever!!! Plz Upload more core java concepts
This is the best that you can do in 7 minutes to explain these relatively confusing concept.
Perfect explanation!! I hope whoever watches this video, for sure they will get the idea of volatile and atomicInteger. Would you explain more about AtomicReference Class and its usage.
such a simple quick explanation. I keep coming on this channel for multi-threading concepts every once in a while
Your videos are awesome .The lucid manner in which the concepts are explained is of the highest quality. Please continue making videos and never slow down.
You have got one more subscriber.... Awesome explanation :)
Thank you!
count me in as well
Metoo
30 likes means, Defog Tech got 30 more subscriber. Awesome.
You deserve more than that. Keep it up.😊👍
Thanks for the 💓....
But I have a complain from you. We, your subscribers, eagerly waits for your videos but it seems you are busy somewhere else. Please do your knowledge spread to us....😃
Lots of love. Keep it up.
i have 8 year exp and preparing for a major interview..all your videos are absolutely to the point. Cheers
Short and Sweet
Whenever I wanted refresh my java concurrency knowledge, this is the place I come in.
Best Explanation, I have searched for volatile for so long, but understand here. Thanks
2 main concepts explained in 7 minutes ,hatsoff!!
This is one of the clearest explanations I got about volatile and Atomic on the internet. Well done.
It could not be more simpler. Thanks a ton.
This is by far the best explanation of synchronization I ever seen, thanks for that!
I wish there is an option to like all the videos in the playlist at once. Amazing explanation keep going please!
The best video about the keyword volatile!! Hands Down
It might also help to share that volatile is enough if there is just one thread writing and multiple threads reading a variable. However, if more than one thread write, then we've those synchronize those.
I never seen this type of video how crystally explain each concept through out the example u have really gud command of mutithreading 👍🙏
really short and sweet,i don't have much clarity about volatile keyword i have searched many sites no one clearly explained like you really pictures,explanation,animations really very understandable way that for providing this vedio sir,expected more content like this sir.Thank you sirrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.................................................
You are very welcome. I'm happy it helped!
Every time I watch a video of you. Only one thought. This guy is a genius.
Making everyone understand small things is not a small thing. Kudos to your way of explanation :)
Excellent, you have nailed it, you explained it so well, so clearly, to the point. Appreciate you effort. Thanks a lot for posting it.
"Best content on Java Advance Topics and Interview Questions" , Please Keep doing more such videos on microservices and AWS.
Very simple and straight explanation good job
Small comment, but quite useful - You don't have to mix volatile with synchronized, because synchronized already has a memory barrier that guarantees visibility of changes that were made within synchronized blocks of the same lock. "On the same lock" is the keyword here
I was surfing for a very long time to understand it better . Your video was the best i have ever seen .
Thank you! I'm happy it helped
The overall content is perfect and to the point but request you if you can add a bit of thread creation and synchronization with thread in older fashion like efficient usage of notify and wait, it will help I am sure a bigger audience
Huge Salute/respect to you sir. I always first like the video before starting and then start watching.
Your explanation does clear all doubts
such a crystal clear simple and short explanation.just waoo
It couldn't have been explained any better..thanks a lot.
This playlist is a treasure
i've never seen any tutorial regarding the multithreading in youtube like u i don't have any word what i said here really mesmerizing wd speechless bdw i am subscribing ur channel please upload the video Collection and OOps Concept and Exception Handling wd internal in depth wd relate the what ever u explain the concept real time like Banking domain and E Commerce
Nice explanation, just to add to it: volatile is not required when u use synchronised block, as synchronised block provides visibility + atomicity
Agreed.. good point
very good explanation with very good example !!! I think I will never forget this concept now -Volatile/Synchronization and AtominInteger.
The Best Playlist for Java Concurrency. Thanks.
Thanks for the clear explanation on Volatile!
Nice tutorial. It clears the concept of volatile and atomic integer
Clear and concise videos. Enjoyed every single minute of this video. The clarity with which the concept is being explained is simply unparalleled. Thank you !!!
Thanks for such wonderful videos.... you are the best in multithreading...
Such an clear explanation ! Succcint and up to the point, before this no one really helped me understand the real implications of the volatile keyword, and many assumed volatile is the equivalent keyword of synchronized, for variables, but no, it is not !
you are amazing man. thank u. Indeed short and sweet.
4:40 if you are sure all access to a variable (all reads and writes) are synchronized on the same object then you don’t need to make it volatile
I am not a 100% sure on this, but maybe because there is no guarantee that the incremented value will be visible to the other thread. Just like in case of the boolean flag, we'll have the visibility problem in this case too.
@@haaarshiiiit If both threads (writer and reader) synchronize on the same object the monitor will establish a happens after relationship which guarantees the change is visible (and also atomic). Same is true for some of the more advanced concurrent utilities (like CHM). Only if you don’t use any of them (or only in some places) you need to deal with the volatile mess.
Fabulous explanation, I finally understood the AtomicInteger. Thanks!! ^^
Today, I actually understood the difference between volatile and atomic variables
all the essence about volatile, synchronized, atomic explained in simple effective way, beautiful :)
Easy to understand, thank you very much, greeting from Indonesia
short and sweet to the point, clear explanation,
Finally I am able to comprehend atomic integer and its use... Thanks a lot! :)
Finally I understood the concept - thank you immensely
Very useful info ,Waiting for u r new videos
Amazing explanation! Tbh one of the best explanation of volatile on the internet!
Great Explanation..! look forward to more technical query explanations.
Awesome explanation, clear voice, pronunciation, apt speech rate, no slow, no high. One question: What if all threads are running in parallel? Like parallel browsers? How can I make only one browser (thread) update the database?
One of the best explanations I have ever heard. Man you are simply awesome. Straight to the point and very clear!!!!!!! 👏👏👏👏 Keep up the great work! I'm subscribed!
Very crisp and clear content! Thank you, thank you !!😊
sexy bro . I was thinking of starting my own channel with java tutorials , but now i ll will just give link to your channel whoever requires any guidance. Great work.
I too share same feeling.. Initially I also wanted to have my own channel but why anybody needs other video.
absolutely great. Paid course couldn't explain it in simple way.
Great content, Just to updates/assignment that all primitives in java except float and double are already atomic so no need to add volatile in front of boolean/int etc.
Nice Info, but mentioning on Compare and Swap (CAS) for Atomic operation would help your user to understand more and how optimistic locking works.
I am late to this channel but i must say the explanations you give are awesome. Thanks for the hard work.
You are really good on explaining complicated things.. I hope you make more video in java and spring, spring boot
Thank you very nice GOD BLESS YOU your service is really great
Thank you for the video. One question/clarification. I don't think we need put volatile if we are using synchronized method (4:53)
true, as per Java Memory Model, variables written to within synchronized block are visible to all other threads using synchronization over same object/lock.
Thanks. I was wondering about that also.
Very useful illustration
It helps me to understand in 2021..
Wow, this is what I'm searching
Very clear and good explanation of the topic, congrats 👏
fantastic explanation !!
keep it up brother....
You're doing an amazing job. Thank you for all your efforts.
Awesome !!!. Very nicely explation of each and every topics of channel uploaded videos.Want to see more and more topics on java concurrent api..Keep it up.
Thank you for the kind words and your motivation sir!
i am subscribed now after watching this video
could nt be explained better , nice one bro!
Just excellent 🙏. It will be helpful if you add some coding examples.
Really nice way of explaining the concepts. Thanks
So glad to have run into this. Great clarity.
Very good. Teaching is an art & you definitely know it.
You have explained the topic very nicely. Thanks. 👍
Excellent explanation like always.. So articulate and to the point.. Cheers!!
Very good and clear explanation, thanks.
Thanks a lot sir. Great learning
well explained, Thank You
very good explaination
Hi Dude, can u please come back and start putting Videos again, i am missing your videos man. pls start some new thing like u started for NOSQL / Cloud / anything at-all i know u will rock in what ever u start 🙂
well done! brief and up to the point
Very nice way to explain such a complex topic.Thanks a lot.
These video's are awesome. Please kindly make a playlist topic wise.
very well explained, liked
Thank you very much for making this video ❤
This video is gold.
Great content, v easy to grasp, thanks for making these videos!!
Best youtuber i ever see
Superb 👌 you explained it truely short n sweet way. Good good
Very nice, thanks bro