Java Video Tutorial 18

Java Video Tutorial 18

FavoriteLoadingAdd to favorites

Code Here: http://goo.gl/M6EOW

Java468x60

Best Java Book : http://goo.gl/FtKp0m

In this Java Video Tutorial, I continue to teach you about Java Threads. I cover how to lock down methods, synchronized, thread pools, scheduleAtFixedRate and numerous other Java Thread methods.

By | 2017-06-03T01:05:08+00:00 June 3rd, 2017|Java Video Tutorials|49 Comments

49 Comments

  1. Kornelije Kovac June 3, 2017 at 1:05 am - Reply

    You’re not explaining anything, just jumping around. These kind of tutorials are aimed for memorizing procedures, and not much helpful for understanding things.

  2. Ashwin Suryawanshi June 3, 2017 at 1:05 am - Reply

    Hello Derek! Greetings. #AnotherAwesomeVideo #YouAreAnAngel  
    When I try to call shutdown() as you did at the end part of this video, it is still printing out the time & date 10 times. Would you be able to tell me where am I going wrong?
    Thanks a lot in advance.

  3. gppen13 June 3, 2017 at 1:07 am - Reply

    Hey, first of all i really like your tutorials, they are amazing. I am wondering if there is a way of having a thread executing everyday lets say at 5 am in the morning, that executes certain method, and that the time that it is executed this thread is configurable from another thread, to change the time that the thread executes this certain task.

  4. Mario Jesus Sanchez June 3, 2017 at 1:09 am - Reply

    Mr. Banas I have a question, when I used the shutdown method to stop all threads for some reason the thread that outputs the time continues while the others are in fact terminated, any thoughts regarding my problem? Also why does my computer has five threads the same four as you and Monitor Ctrl-Break. I would also like to thank you for all your videos, they are great

  5. A. Smith June 3, 2017 at 1:09 am - Reply

    Hi Derek, I am a bit unclear on what benefit the Runnable class offers. For example, why implement Runnable over implementing the Thread class as depicted in your example above(i.e. at 0.54 secs into this video).
    Kindly clarify.

  6. Peter Kurtosi June 3, 2017 at 1:14 am - Reply

    Excellent tutorial, Thank you Derek. But I swear, I have never heard you to breathe. 🙂
    Like a pearl-diver. One breath / 10 minutes. 🙂

  7. Mensaaa Bektic June 3, 2017 at 1:15 am - Reply

    hi Derek, nice video, i’m learning a lot from you. My question is did you all learn this from the Head First Java book?

  8. grimlek June 3, 2017 at 1:15 am - Reply

    Surprised that you didn’t go over ExecutorService or Executor for threads…….

  9. Kieran Woodward June 3, 2017 at 1:16 am - Reply

    I keep coming back to this video to recap on threading and it cracks me up every time because I can imagine Derek checking his calendar every 10 seconds xD

  10. Yasin Uygun June 3, 2017 at 1:16 am - Reply

    Derek, can you make a detailed thread tutorial in java, because there are so many classes about threads and I am confused about where to use each one. or can you advice a good resource to learn all about threads?

  11. Paweł Monster June 3, 2017 at 1:19 am - Reply

    Just for information, I have received fifth Thread. His name is Monitor Ctrl-Break. 🙂

  12. Dmitry Avgustis June 3, 2017 at 1:21 am - Reply

    Hi Derek, I was wondering if you could make video about java dynamic proxy api (java.lang.reflect.Proxy)? You have the video about proxy design pattern, but it seems like a little bit different thing. So it’s sort of request by me 🙂

  13. Hakan Hatipoğlu June 3, 2017 at 1:22 am - Reply

    Hi Derek, at the end of the video there is one Time:9:33:38 even if we shutdown all the threads.Can you explain the reason??

  14. Fern Moore June 3, 2017 at 1:23 am - Reply

    +Derek Banas Thanks for the videos. I know these are several years old but can you please help me. At the bottom of LessonEighteen I used :

    try
    {
    Thread.sleep(2000);
    }
    catch(InterruptedException e) {}

    but it doesn’t stop the code after 20 seconds. It keeps running forever. Does that mean its throwing an exception every time and just continuing on? Or has something changed in the newer version of Java? I compared the rest of the code and everything is the same so I’m not sure what is going on. eventPool.shutdown(); did turn it off after a couple timestamps printed though. I didn’t notice before but it was also the same for LessonSeventeen.

  15. Fanjing Liu June 3, 2017 at 1:23 am - Reply

    IMPORT STATIC JAVA.UTIL.CONCURRENT.TIMEUNIT.*;

  16. Youssef Samwel June 3, 2017 at 1:23 am - Reply

    derek, do you mean that multiple threads can access the same thread.

  17. Vishal Patel June 3, 2017 at 1:25 am - Reply

    Hi Derek this are some of best tutorials i have watch. Thank for all of this videos. I have couple of questions though. when you are implementing Runnable in the PerformSystemCheck in this video and GetTheMail in the last video.
    My question is how is that you are implementing Runnable without actually creating an interface file called Runnable?
    Also when you are using extends Thread, is Tread builtin class used for inheritance and it is the SuperClass?
    Thank you for all of you help!

  18. Amit Singh June 3, 2017 at 1:26 am - Reply

    if i don’t wanna use eventPool.shutdown() , what method i should use then?

  19. Shubham Kahal June 3, 2017 at 1:27 am - Reply

    Hey Derek, is it worth the time to memorize the libraries, or do most people just look it up on Java documentation?

  20. element74 June 3, 2017 at 1:31 am - Reply

    you cut out the video where you added static after import. lol… that error scared me until i checked out your website and someone had the same error. You should add annotation about adding static in that part. Right when you executed the code.

  21. adi elisha June 3, 2017 at 1:31 am - Reply

    all your videos are great – you’re a great teacher, but this one in particular was perfect because at about @07:30 you ask us if we know what happend, and you make us think – making the whole video interactive.

    great job, keep it up!

  22. Ashwin murali June 3, 2017 at 1:32 am - Reply

    This saved me the trouble of going through the huge Java book.. Thanks a lot Derek! 🙂

  23. DBvype June 3, 2017 at 1:33 am - Reply

    Thank you Derek for the Java Video Tutorial Series.

  24. Shawn Lupoli June 3, 2017 at 1:34 am - Reply

    Derek, thanks again for the video. I’m good with all, but the lock. If I remove the lock, the output is the same. If I put a sleep for 5 second between "lock" and "unlock", I get the same output, EXCEPT "Checking Calendar" and "Checking Mail" are swapped. I don’t get why. I was expecting Mail to be much later, and maybe no "Checking Calendar" at all. I’m just trying to prove locked works. (Thank you!!)

  25. Bernardo Galvão June 3, 2017 at 1:34 am - Reply

    Hi Derek. I like that you do tutorials on everything! My question is, can you make a Thread wait for the output of another based on some condition? More specifically, I want two Threads to exchange information every 10 iterations, when one Thread is slower than the other.

  26. SKtheGEEK June 3, 2017 at 1:37 am - Reply

    i have a question –
     if i return a class from a function and i have a Object as return type . so as its the super class then i can return any class but i cant access the values of child class through the returned object as its "Object " class . so then i do a conversion like child class <veriable>=(child class) <returned object> . so can i now access the values of child class . or will it be lost at the time of the return . like of we assign double to int type then data loss is done . and even if we change that int to double we will not be able to get the lossed value .
    please do reply .

  27. Andrew Muller June 3, 2017 at 1:38 am - Reply

    Hey Derek. Can you please add an annotation to this video at 7.05-7.10 showing how you added the word static to the import TimeUnit. Look me ages to figure out why it wasn’t working hahah.

    Apart from that, thank you very much for putting in the time and effort to make these videos 🙂 I really appreciate it

  28. Safeer Mughal June 3, 2017 at 1:40 am - Reply

    Hi Derek i am struggling to make a online banking system, where i can deposit and withdraw money for accounts such as current and savings i need to have only 4 classes and i have account, bank account, current and savings. please could you help? thanks!

  29. Eli Gerzman June 3, 2017 at 1:42 am - Reply

    what if i just want a game or some sort of activity to work for  two minutes?

  30. Brian Tep June 3, 2017 at 1:43 am - Reply

    PROTIP: buy some starbucks and watch the video at 2x

  31. Rishi Swethan June 3, 2017 at 1:43 am - Reply

    +Derek Banas wont it be amazing if we can close the running program when the user pressed enter or something like that!. It also opens up lot of options for games… very exited!
    How do i do it?did i miss something or is it in one of the next videos?

  32. Strugglr Brah June 3, 2017 at 1:44 am - Reply

    +Derek Banas Hey Derek for some reason I am getting 5 Threads instead of the expected 4. It is putting out main, Monitor Ctrl-Break, pool-1 thread-1,pool-1 thread-2,pool-1 thread-3.

    Google doesn’t seem to tell me what Monitor Ctrl-Break is for Threads. Can you help me figure this out?

    Thanks

  33. Vedanta Maha Karuna June 3, 2017 at 1:45 am - Reply

    my brain can’t remember all these syntaxes

  34. TheBlue8ird June 3, 2017 at 1:46 am - Reply

    the .sleep(miliseconds) says how much time the thread will RUN or like hold?

  35. Zachery June 3, 2017 at 1:48 am - Reply

    I’d like to think that I’m a decent C++ programmer. But you move way to fast in these tutorials sometimes. And you don’t fully explain concepts. I don’t know how people with little to no programming experience can learn anything from these. This comment wasn’t intended to come off as rude. Just my honest opinion.

  36. Sven Austen June 3, 2017 at 1:49 am - Reply

    All right, one more question, this time a basic one: When I install Eclipse on my USB-Stick, does it use the RAM of the Computer or does it have to work with the space on the Stick?

  37. Luis Gamez June 3, 2017 at 1:49 am - Reply

    So pretty much this is how you deal with Deadlocks, correct?

  38. K G June 3, 2017 at 1:51 am - Reply

    I just wrote all the same code as the video played, but I have 5 threads.
    main
    Monitor Ctrl-Break
    pool-1-thread-1
    pool-1-thread-2
    pool-1-thread-3

    What is Monitor Ctrl-Break?

  39. TheMrberrybanana June 3, 2017 at 1:52 am - Reply

    So what exactly are threads, I have been getting kind of confused the last couple tutorials and also what is Runnable?

  40. BCwithPC June 3, 2017 at 1:54 am - Reply

    PSA @ 7:07 make if your eclipse isn’t recognizing "SECONDS" make sure to say "import static java.util.concurrent.TimeUnit;" instead of "import java.util.concurrent.TimeUnit;"

  41. Amir Shahbabaie June 3, 2017 at 1:55 am - Reply

    Man You are wonderful!!!

  42. numele meueste June 3, 2017 at 1:55 am - Reply

    Hello why do I have 5 threads ? 

    main
    Monitor Ctrl-Break
    pool-1-thread-1
    pool-1-thread-2
    pool-1-thread-3

  43. Kiem Nguyen June 3, 2017 at 1:55 am - Reply

    Hi Derek. Thanks for the great tutorial. You’re the Best teacher on the net, I really like the way you explain stuff. I’m also getting 5 Threads like other people instead of the expected 4 threads. I would like to know why there is an additional thread beside the main thread. Thanks.

  44. Youssef Samwel June 3, 2017 at 2:00 am - Reply

    Derek, when should i use synchronized

  45. Fellipe Freire June 3, 2017 at 2:00 am - Reply

    This final part wasn’t very clear.
    try{Thread.sleep(20000);}catch(…){} //Will not shutdown your Thread Executions.
    eventPool.shutdown //This will
    //So if you put this line after the try block, this part will execute and finish all your Thread Executions after the said 20 seconds.

  46. mudit rai June 3, 2017 at 2:01 am - Reply

    while executing the PerformSystemCheck.java this error is showing ..what to do.?Why is it showing this errror?

    javacPerformSystemCheck.java
    PerformSystemCheck.java:5: error: PerformSystemCheck is not abstract and does not override abstract method run() in Runnable

    public class PerformSystemCheck implements Runnable

  47. ULTIMvines June 3, 2017 at 2:01 am - Reply

    Derek thanks for the videos , i’m learning a lot , the best part is im not just learning the syntax , i’m learning how to use them for real in my program which is the most important part while learning a language i believe. Now the doubt , in the enhanced for loop for (Thread i: listOfThreads) i used " Arrays.binarysearch(listOfThreads,i) to find out the index of my thread but i got an error.WHY?!

  48. Sohel Ahmed June 3, 2017 at 2:03 am - Reply

    Finally i found you boss

  49. Waseem Swaileh June 3, 2017 at 2:04 am - Reply

    Hello Derek .. 
    I used the try block withe ScheduledThreadPoolExecutor.
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) { }
    but it still run forever .. I don’t know what is the problem 🙁

Leave A Comment

*