Java Threads - Creating, starting and stopping threads in Java

  Рет қаралды 142,139

Jakob Jenkov

Jakob Jenkov

Күн бұрын

Пікірлер: 178
@mostinho7
@mostinho7 3 жыл бұрын
9:00 Stopping threads Synchronized keyword will stop threads executing the method concurrently but if a new 2nd object is created, then two different threads can call the method concurrently on each of the object instances. So synchronized only works if multiple threads call same object 8:30 the native way of stopping a thread will stop a thread in an unkown state. Implement a runnable that has a stop function instead of using the default stop method. The custom stop function sets a stop requested variable, then the runnable run method can keep checking if a stop has been requested or not and terminate on its own terms (saving any state before stopping). 12:00 the main thread can terminate, but as long as any of the threads it started are still running, then the JVM will stay running. Daemon threads will NOT keep the jvm alive if they are the last thread running, so if you want the jvm to stop running after all other threads have terminated thread.setDaemon(true) 14:10 can make main thread wait for another thread by using thread.join 15:15 OS threads vs more lightweight threads project loom (fibers)
@luckyluke2483
@luckyluke2483 4 жыл бұрын
hey Jakob. I usually give a visit to your webiste at work on a weekly basis. just wanted to say thanks for the effort. It has helped me a lot at work
@JakobJenkov
@JakobJenkov 4 жыл бұрын
You are welcome :-) Happy my tutorials help people out there :-)
@JanChodura68
@JanChodura68 Жыл бұрын
Still great! Thanks. One small thing. I added print to main method after calling run of thread and now voiala you can see main thread is finished but thread still runs and shows its print
@mortbringsli
@mortbringsli 3 жыл бұрын
I have to thank you for the fantastic work you do here. This video (along with the related article) both summarized and was more informative than the last three lectures on multithreading in my comp-sci course. People like you make learning easy, and are a real gift to the world.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you very much! - and I am happy that my tutorials have helped you learn!
@Eduardado
@Eduardado 3 жыл бұрын
Jakob, this was an amazing explanation. Thanks a lot :D. Subscribed!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great! And thanks! :-)
@JonasKeil
@JonasKeil 2 жыл бұрын
Another awesome video, thanks Jakob!👏
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You are welcome! :-)
@hailiu2295
@hailiu2295 4 жыл бұрын
Thanks for your effort. I also like watching your textual tutorials. As a fresh Java Programmer, I acquired more new knowledge from your tutorial. Thanks a lot!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thanks! - Great to hear :-)
@destro5990
@destro5990 3 жыл бұрын
Loved it, threads have always been hard to grasp but you made it way easier
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great ! 😊
@enable4
@enable4 4 жыл бұрын
I just don't have words to express all my gratitude for all your work
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you! :-) The words you did have are still very much appreciated :-)
@sebastiantomczyk4577
@sebastiantomczyk4577 Ай бұрын
Does the textual version include all the informations that KZbin course have(I mean for entire JAVA THREADS, not just for this episode)? I prefer textual version more but I dont want to miss any bit of what YT course gives. Thanks for the answer!
@JakobJenkov
@JakobJenkov Ай бұрын
Usually the articles and videos have the same amount of details 😊
@sebastiantomczyk4577
@sebastiantomczyk4577 Ай бұрын
@@JakobJenkov thank you 👍🏻
@arisdideambemou1508
@arisdideambemou1508 3 ай бұрын
Thanks for your video. It was amazing a bring a lot a knowledge !
@JakobJenkov
@JakobJenkov 3 ай бұрын
Thanks!! Glad you liked it !! 😊
@sonalgupta7083
@sonalgupta7083 2 жыл бұрын
When and how the runnable stops the thread after checking the stopRequested variable?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Then the Runnable.run() method exits (returns) - meaning it simply finishes executing - then the Thread executing the Runnable stops automatically.
@someshpandey428
@someshpandey428 2 жыл бұрын
Fantastic Playlist!! Hope you'll continue making these awesome videos!! Your website and content there is superb as well !! One thing, Is there a git repo for the code snippets etc. used in this playlist? It will be much helpful.
@gaomingt
@gaomingt 3 жыл бұрын
When using lambda expression to create a new thread, isn't it more readable to implement Runnable interface like the following code snippet? Thread thread = new Thread ( () -> { System.out.println("Lambda running"); System.out.println("Lambda finished"); } ); thread.start(); Anyways, thanks for making this awesome multithreading series. High quality content!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
That is a question of personal style preference. Your way can work just fine too :-)
@burakb8708
@burakb8708 3 жыл бұрын
Thanks for your explanation.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome
@singhvertika8167
@singhvertika8167 4 жыл бұрын
Your videos are just outstanding..I feel more confident in java concurrency now..thanks
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you very much !! I have more videos on Java concurrency coming soon !!
@supercrazysquid
@supercrazysquid 4 жыл бұрын
Thank you! Amazing tutorial and easy to follow!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you - glad it was helpful! :-)
@mouradlaraba
@mouradlaraba 3 жыл бұрын
thanks a lot sir for your generosity, i learn a lot from your courses, big hug for you :)
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Glad to be able to help :-)
@BillPark-ey6ih
@BillPark-ey6ih Жыл бұрын
I appreciate your tutorials. They are really helpful as I had no clue during the lecture haha. Also, your videos are very well organized and concise unlike many other videos. Thank you!
@JakobJenkov
@JakobJenkov Жыл бұрын
You are welcome! ... and thank you for taking the time to tell me! :-)
@GeoffClark
@GeoffClark 3 жыл бұрын
THANK YOU so much. This solved a "freezing" issue when I was trying to use media in my JSwing. So helpful!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great ;-)
@alihosseinkhani2671
@alihosseinkhani2671 2 ай бұрын
thank you. there course is helping insane!
@JakobJenkov
@JakobJenkov 2 ай бұрын
Thank you 😊😊
@MrDe0
@MrDe0 3 жыл бұрын
very straightforward !! amazing
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I try my best to make the content easy to understand :-)
@PriyasKitchen21
@PriyasKitchen21 3 жыл бұрын
how to stop freezing ui using multithreading using java
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You would normally delegate the work you have to do to a background thread, rather than executing it directly in the UI thread. When the background thread finishes its work, the last thing it does it to send a message back to the UI thread with the result. I have described how you do that in JavaFX (see link below). I will be similar in other UI toolkits such as Java Swing, Java AWT or SWT. tutorials.jenkov.com/javafx/concurrency.html
@St.Pa-al
@St.Pa-al 8 ай бұрын
Good stuff, just stumbled upon you Jakob.
@JakobJenkov
@JakobJenkov 8 ай бұрын
Thank you ! :-) Glad you liked my videos :-)
@swagatpatra2139
@swagatpatra2139 3 жыл бұрын
Thanks, nice video.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! Glad you liked it! :-)
@Das.Kleine.Krokodil
@Das.Kleine.Krokodil Жыл бұрын
Great videos, thanks! Are there source codes?
@JakobJenkov
@JakobJenkov Жыл бұрын
There are some, here: github.com/jjenkov/java-examples
@kaka_tutorails8765
@kaka_tutorails8765 6 күн бұрын
Thank man I learn something from you.
@SouthernSeneca
@SouthernSeneca 18 күн бұрын
This playlist is a jackpot for learning concurrency in Java, thanks for creating these
@JakobJenkov
@JakobJenkov 17 күн бұрын
Great ! Thanks :-)
@nathansmalley8433
@nathansmalley8433 4 жыл бұрын
Great instruction!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you very much !!!
@shubhamagarwal1434
@shubhamagarwal1434 4 ай бұрын
God of Concurency..i have bene flowing you since my 2014 when you used to write blog post only...by going through your post i attend interview like a LION when they ask mutithreading qns....Thanks a Lot form 10+ yrs exp guy from BLR,India.
@JakobJenkov
@JakobJenkov 4 ай бұрын
Thanks! :-)
@smellthel
@smellthel 3 жыл бұрын
thanccc
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome :-)
@justvibhor3743
@justvibhor3743 10 ай бұрын
Thanks a lot i was struggling with that !!
@JakobJenkov
@JakobJenkov 9 ай бұрын
You are welcome! :-)
@WiseFatOwl
@WiseFatOwl 4 жыл бұрын
Hello Jakob.. Loved this simple and straight to the point tutorial. Thank you for making this!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Cool - you are welcome :-)
@aaavalenca
@aaavalenca 3 жыл бұрын
12:18 "And keeps the Java Virtual Machine ~alive~", says he, as if he was a mad scientist. Jokes aside, wonderful videos! It's been of great help :))
@JakobJenkov
@JakobJenkov 3 жыл бұрын
;-)
@waqasahmed8660
@waqasahmed8660 4 ай бұрын
Thank you for this amazing tutorial that explains a lot of important concepts related to Threading in Java. Much appreciated.
@JakobJenkov
@JakobJenkov 4 ай бұрын
You are welcome !! 😊 Happy it was helpful to you !! 😊
@SoeaOu
@SoeaOu 3 жыл бұрын
thanks, this series is much better then reading the boring "java concurrency" book short and to the point examples you can follow along, 10/10
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-D ... I hope my voice doesn't make you fall asleep :-D
@heclosty-wk3bj
@heclosty-wk3bj Жыл бұрын
Thanks a lot, but do you have GitHub source, so we can practice with you
@JakobJenkov
@JakobJenkov Жыл бұрын
The Java examples I have in GitHub are found in this repo: github.com/jjenkov/java-examples
@heclosty-wk3bj
@heclosty-wk3bj Жыл бұрын
@@JakobJenkov cool, but it doesn't have this video's code, so I have uploaded in your repo
@matthewsaucedo2471
@matthewsaucedo2471 9 ай бұрын
@@heclosty-wk3bj @JakobJenkov Can you merge his PR?
@josephkwagilwa8449
@josephkwagilwa8449 2 жыл бұрын
Great Content for Java Concurrency
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks, Joseph :-)
@subbunittala2012
@subbunittala2012 3 жыл бұрын
this is just awesome , Jenkov .. i usually go through your website ..thank you very much for sharing knowelege at diamond level !
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Hi Subbu! Thank you for your kind words! I am happy that my articles and videos are helpful for you! :-)
@_graymatter__
@_graymatter__ 4 жыл бұрын
Good to have a revision on this concept. Thanks for you effort.
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Ah, so you noticed that this video replaces an older video I've made on this topic?? ... which had text flickering, and covered less topics etc. ;-)
@رياحالهاشمية
@رياحالهاشمية Жыл бұрын
From Saudi Arabia thx🇸🇦🇸🇦🇸🇦 u help me to understand well my lessons
@JakobJenkov
@JakobJenkov 11 ай бұрын
You are welcome :-)
@lifesport1380
@lifesport1380 2 жыл бұрын
Thank you very much❤️
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You're welcome 😊
@chirag2819
@chirag2819 8 ай бұрын
Thank you for saving me from those dry technical books.
@JakobJenkov
@JakobJenkov 8 ай бұрын
You are welcome ! ;-)
@andgoleczka
@andgoleczka 3 жыл бұрын
Very nice educational videos. I like how you explain things, understandable language and powerful examples! Well done Jakob!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you very much! :-)
@WhiteBerry
@WhiteBerry 3 жыл бұрын
Hi Jakob, thanks for your clear explanations - while I still can't get my head around this I believe I may need to take things a little slower in order to fully understand your code examples. Nevertheless, thank you for your explanations and keep it up! :)
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks ! ... what exactly can't your get your head around?
@peshutanpavri1599
@peshutanpavri1599 Жыл бұрын
Fantastic playlist and great info, thank you so much, your other website has so much amazing information. I only have one question about best practices and organising code that will be multi-threaded. Most of the time, I would implement a runnable interface, or use a lambda/method reference. If I have some long running task simulating processing lots of data etc.. Should the core logic be inside the run method or should the run method be in a separate class that only deals with the logic of handling threads. Because I may a split a task between multiple threads ? For example, If I get some data from a database or an api, then I have a huge list of data that i want to process, say I have a method called processData, should that logic be inside run or should i call processData from run ? Just wanted to know if there are any best practices to organising this. Also server side multi-threading seems to be different ? Because there is no main UI thread or UI rendering server side, I guess it would just be large computations ? Making a request to a DB could be on the main thread itself ? Especially as it sequential ? In order to respond to a request, I would need to wait for database to respond anyway, I am so sorry i just had one question about organising multithreaded code but went on a tangent, Your videos and online tutorials are so helpful Thank you
@JakobJenkov
@JakobJenkov Жыл бұрын
Sorry about the late reply! ... I would keep the run() method as small as possible, and move the application logic to separate classes / objects. On the server - it depends on the threading model used by the web server you are using. If the web server uses one thread per connection, you can block that thread and call a database or remote HTTP / REST API from inside that thread. However, if the web server uses a single-threaded design (as Netty or Undertow does), then you should NOT call a database or remote HTTP / REST API from that thread, but instead call that from a background thread, so you don't block the single thread serving requests from the users.
@peshutanpavri1599
@peshutanpavri1599 Жыл бұрын
@@JakobJenkov Thank you, not to worry, I appreciate you taking the time to get back to me. Is there anyway you have some more detailed info / video about how NIO networking works ? Im really struggling to understand the fundamentals and how to get started, I want to build my own web server Thanks
@willemsmit2929
@willemsmit2929 4 жыл бұрын
Much Appreciated! Helped a lot.
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Great - glad it helped! :-)
@asdenakisolmonkate9467
@asdenakisolmonkate9467 Жыл бұрын
It is amazing continue
@JakobJenkov
@JakobJenkov Жыл бұрын
Thank you 😊
@KratosProton
@KratosProton Жыл бұрын
Great explanation!
@JakobJenkov
@JakobJenkov Жыл бұрын
Glad it was helpful ! :-)
@journeytothedream6127
@journeytothedream6127 3 жыл бұрын
Lots of love from the bottom of my heart
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome! I am glad my tutorials help people out there! :-)
@gregorytippett9692
@gregorytippett9692 3 жыл бұрын
Exceptional tutorial. Very clearly explained & well-organized examples!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you! :-)
@MohitKhare
@MohitKhare Жыл бұрын
thank you Jakob
@JakobJenkov
@JakobJenkov Жыл бұрын
You are welcome! :-)
@paulisaichuk5034
@paulisaichuk5034 Жыл бұрын
Excellent video, great job, thanks!
@JakobJenkov
@JakobJenkov Жыл бұрын
Thanks - glad you liked it! :-)
@chingiskhant4971
@chingiskhant4971 3 жыл бұрын
This is great!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks! :-)
@HariKrishnaMajety333
@HariKrishnaMajety333 2 жыл бұрын
Hey Jakob! Thanks a ton for these Amazing lectures! Your explanations are very clear. Btw, do you plan on making videos about Java Futures?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks ! Yes, at some point I will get to Java Future too !
@HariKrishnaMajety333
@HariKrishnaMajety333 2 жыл бұрын
Thanks Jakob! Videos on CompletableFutures in Java would be great!
@whereispie
@whereispie 3 жыл бұрын
Thanks 👍❤️
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You're welcome 😊
@SkiesTribune
@SkiesTribune Жыл бұрын
Adding the synchronized keyword on both flag control methods ensures immediate stopping of threads that share the same runnable (no more printing)(t2,t1,t1,t2,t2,stop) and removing them will allow an extra sout to be printed even after stopping (t2,t1,t1,stop,t1,t2) If you synchronize the runnable sleep() method, this will ensure each thread prints a statement in an orderly fashion (t1, t2, t1, t2, t1,stop). If you synchronize the run() method itself, then one thread will be printing statements as it's not gonna leave the shared resource at all(t1,t1,t1,t1...stop).
@RoadRoller01
@RoadRoller01 3 жыл бұрын
great video
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thank you very much! :-)
@MohammedMutwakil
@MohammedMutwakil 3 жыл бұрын
for 3 days I'm looking for a person who can explain what is this thread and how I can use it, finally I understand it, you are really amazing how you make it very simple, keep going and never stop, thank you very much for your effort.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I am glad my video helped you! :-) ... nothing more frustrating than browsing / googling around for answers to a problem that you know lots of other people have the answer to, but you just can't find it. Believe me - I have tried that a lot during my 20+ years as a Java developer :-D
@MohammedMutwakil
@MohammedMutwakil 3 жыл бұрын
Hi @@JakobJenkov, I have question please, the Thread in Android has something called Handler, is this Handler is used in Java? if it's, and you cover it please show me in which video.
@ahsanmuhammad7453
@ahsanmuhammad7453 2 жыл бұрын
Thank you for these well explained videos :)
@JakobJenkov
@JakobJenkov 2 жыл бұрын
You're very welcome! :-)
@minasalah8210
@minasalah8210 3 жыл бұрын
thank's
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome :-)
@anthonysouza-pl5pm
@anthonysouza-pl5pm 7 ай бұрын
bro randomly went to another level idk what is happening
@JakobJenkov
@JakobJenkov 7 ай бұрын
Whar do you mean ? 😊
@Hubertoom
@Hubertoom 3 жыл бұрын
So obvious, so clear. Great job!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks - glad it was easy to understand! :-)
@Hubertoom
@Hubertoom 3 жыл бұрын
@@JakobJenkov I'm learning from Hyperskill by JetBrains and often when some topic is hard or not enough elaborated or sometimes vague described peoples putting references to your and baeldung sites :) It's almost always makes things clear, you have gift to explain hard topics. As Aristotle said "Teaching is the highest form of understanding." You got it :) Thanks a lot for your job!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome !! Glad my tutorials are helpful to people out there ! :-)
@nelisiwemkhatshwa1689
@nelisiwemkhatshwa1689 3 жыл бұрын
creating an accesses functions for the inserting and the updating functions that can be callable outside the jar
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I don't think I understand what you mean?
@Golipillas
@Golipillas 3 жыл бұрын
Thanks Jakob, incredible teacher.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome :-)
@RagingAcid
@RagingAcid 3 жыл бұрын
This is a fantastic video. The chapters are such a nice touch
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks !! 😊😊
@vojindjukic2719
@vojindjukic2719 4 жыл бұрын
Very good, thank you sir
@JakobJenkov
@JakobJenkov 4 жыл бұрын
You are very welcome :-)
@aveatdj
@aveatdj 3 жыл бұрын
great explication thank you
@JakobJenkov
@JakobJenkov 3 жыл бұрын
You are welcome!
@diogosilva8219
@diogosilva8219 3 жыл бұрын
this really helps thx a lot keep it up!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Great! ... will try to publish more videos in the future, but I don't have as much time at the moment as I used to... but I am recording a video right now, so I will release a new video soon!
@blackcitadel37
@blackcitadel37 2 жыл бұрын
14:15 Isn't it using .join( ) on a daemon thread a bad idea?
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Well, if the thread calling join() is kept alive (not terminating) as long as the daemon thread is running - what could happen? ("what could possibly go wrong?" :-D )
@kurisuta1305
@kurisuta1305 Жыл бұрын
Amazing! I have an interview for a job that specializes threads, and your video is HEAVEN sent :D
@JakobJenkov
@JakobJenkov Жыл бұрын
Great timing :-)
@eduardojavierlatorrevandep4583
@eduardojavierlatorrevandep4583 2 жыл бұрын
Such a good tutorial!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Great to hear it is helpful for you! :-)
@davidchen6869
@davidchen6869 2 жыл бұрын
Hey Jakob, massive thanks for the help! I do, however, wonder how come the ... are still printed after the printing of "stop requested". How would one be able to prevent this from happening?
@alessandro-belottidigital7161
@alessandro-belottidigital7161 2 жыл бұрын
if you'd like to prevent this behaviour you'd basically need some sort of shared boolean variable between the two threads and do stuff according to it
@matus6681
@matus6681 3 жыл бұрын
Great video! Is there and easy way how to explain difference in Java vs Python threading module? As Python thanks to GIL is single threaded what does it mean in comparison to the Java? In other words what is possible to achieve with java that is not possible with python in terms of multithreading? Thanks!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Hi Matus, I don't know Python well enough at this point to say what the difference between Java threads and Python threads are, unfortunately.
@MarceloAX
@MarceloAX 9 ай бұрын
The clarity, conciseness and simplicity of your videos and articles are a immense contribution for tech!! Thank you so much for your effort!!
@JakobJenkov
@JakobJenkov 9 ай бұрын
Thank you very much for your kind words! :-)
@sebon11
@sebon11 3 жыл бұрын
Greeeeat explanation!
@JakobJenkov
@JakobJenkov 3 жыл бұрын
Thanks :-)
@xavierdupont2926
@xavierdupont2926 Жыл бұрын
Are there pros and cons in using the same runnable instance to instanciate multiple threads?
@JakobJenkov
@JakobJenkov Жыл бұрын
If your Runnable instance has any member variables, those would be shared among the threads running that instance. Most often you do not want to do that. You want each thread to have its own Runnable instance (at least that is the most common use I have seen).
@xavierdupont2926
@xavierdupont2926 Жыл бұрын
@@JakobJenkov Thanks, I understood that better when I watched your video on the Java memory model.
@vivekpanday
@vivekpanday 2 жыл бұрын
Awesome as usual 👍
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thanks! :-)
@LyashenkoSergiy
@LyashenkoSergiy 4 жыл бұрын
Very informative!
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thanks ! :-)
@kmdsummon
@kmdsummon 3 жыл бұрын
Why do you create stoppable runnable to stop if the same effect can be done with interrupt, but interrupt is better in all ways?
@JakobJenkov
@JakobJenkov 3 жыл бұрын
calling interrupt() on a thread only works if A) The thread is blocked somewhere e.g. in a wait() call which respects the interrupt signal. B) The thread does itself check its own interrupt signal. While I could have used the interrupted flag on a thread to signal it to stop, I prefer making the signals more explicit. This way you know that the stop signal does not mean it should immediately abort everything it does *in the middle of its loop*, but can do so *at the boundaries (beginning) of its loop*. There is a slight difference there, although I understand it can be hard to see it until you know its there :-)
@maxresdefault8235
@maxresdefault8235 4 жыл бұрын
GREAT TUTORIAL
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Thank you very much! :-)
@yog2915
@yog2915 4 жыл бұрын
Good stuff thanks to your blogs my understanding of concurrency is clear
@JakobJenkov
@JakobJenkov 4 жыл бұрын
Great - that makes me happy to hear ! :-) I have more videos on Java Concurrency coming !
@zhaoyinqin3728
@zhaoyinqin3728 3 жыл бұрын
Can you provide an example where 2 threads calls requestStop() or/and isStopRequested() at the same time? I can't think of an example since it is the runnable which calls the method, not the thread, which leads to another question, why do we need the synchronized keyword here?
@JakobJenkov
@JakobJenkov 3 жыл бұрын
if the stopRequested variable is a member variable of the Runnable implementation, then yes, the threads will share that member variable. Thus, when one thread is requested to stop, the other thread will stop too. Normally you do not pass the same Runnable implementation to different threads, because you often have some control logic inside them that you want to be controllable for each thread. Rather, if the threads are to share objects, these objects are accessed from inside the Runnable implementations.
@zhaoyinqin3728
@zhaoyinqin3728 3 жыл бұрын
@@JakobJenkov Thank you
@jefferycroom7536
@jefferycroom7536 3 жыл бұрын
I am linking this KZbin page to my class in a discussion about Violent Deaths and threads and not using the variable for Java thread. This is a great example of some of the information we are covering. Great Job on explaining.
@JakobJenkov
@JakobJenkov 3 жыл бұрын
I am not sure I understand exactly what your class is about?
@jefferycroom7536
@jefferycroom7536 3 жыл бұрын
@@JakobJenkov we are going over Creating threads and we were going over Violent stops using just a stop method() and why not yo use it. We are also going over starting Java Threads
@azizbekibnhamid642
@azizbekibnhamid642 Жыл бұрын
Thanks
@JakobJenkov
@JakobJenkov Жыл бұрын
Welcome :-)
@juandebenedetti2884
@juandebenedetti2884 2 жыл бұрын
Jakob, I am Latino and I have to tell you that you are the best and most detailed in explaining. I am super grateful to be able to learn from your videos and website. Graciass!!
@JakobJenkov
@JakobJenkov 2 жыл бұрын
Thank you very much! :-) I am happy that my videos are helpful for you! :-)
Java Virtual Threads
9:06
Jakob Jenkov
Рет қаралды 38 М.
БЕЛКА СЬЕЛА КОТЕНКА?#cat
00:13
Лайки Like
Рет қаралды 2,6 МЛН
Ozoda - Lada ( Ko’k jiguli 2 )
06:07
Ozoda
Рет қаралды 15 МЛН
小丑妹妹插队被妈妈教训!#小丑#路飞#家庭#搞笑
00:12
家庭搞笑日记
Рет қаралды 38 МЛН
The Java Memory Model - The Basics
23:41
Jakob Jenkov
Рет қаралды 128 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 946 М.
Multithreading in Java Explained in 10 Minutes
10:01
Coding with John
Рет қаралды 928 М.
Java Happens Before Guarantee - Java Memory Model - Part 2
26:13
Jakob Jenkov
Рет қаралды 59 М.
Java Concurrency and Multithreading - Introduction
14:32
Jakob Jenkov
Рет қаралды 251 М.
Java 21 new feature: Virtual Threads #RoadTo21
33:35
Java
Рет қаралды 64 М.
Node.js is a serious thing now… (2023)
8:18
Code With Ryan
Рет қаралды 650 М.
Java threads 🧵
16:01
Bro Code
Рет қаралды 113 М.
Concurrency vs Parallelism
9:29
Jakob Jenkov
Рет қаралды 66 М.
БЕЛКА СЬЕЛА КОТЕНКА?#cat
00:13
Лайки Like
Рет қаралды 2,6 МЛН