In this Java Video Tutorial, I continue to teach you about Java Threads. If you missed the last part, watch it first here last Java Tutorial.
Today I cover how to lock down methods, synchronized, thread pools, scheduleAtFixedRate and numerous other Java Thread methods.
Use the code that follows the video to make it easier to follow this tutorial. It is heavily commented and will help you.
If you like videos like this share it [nttfblike]
Code From the Video
LESSONEIGHTEEN.JAVA
CHECKSYSTEMTIME.JAVA
PERFORMSYSTEMCHECK.JAVA
Please put the codes of Java Video Tutorial 18 on this page.
Fixed it. Thanks for pointing out that error
Hi, great videos! Just wondering about why the TimeUnit library has to be static? Line 3 in JavaLessonEighteen.
It doesn’t have to be. I’m not sure why I did that? I improv my way through these tutorials and on occasion I do something silly
Ok, thank you for quick answer! And the tutorials are just great, have been through 1-24 now and my understanding of Java Programming is so much better than after all the other java tutorials I’ve tried out!
Thank you. I’m very happy to hear that. I always wonder who my competition is. I don’t watch any other tutorials so I don’t know what I’m up against.
There are alot of other talented guys making tutorials on Java, but your pace suits me very well. The others are often a bit slow. Also the fact that you edit your tutorials is as far as I can tell very rare but very nice for us viewers!
Well, thank you very much. It is time consuming to edit them, but I think the extra time sets me apart. I’m glad you took the time to say Hi π
good work sir, excellent
Thank you very much π
hello derek, i am getting error on line no 30,32,34 . the eclipse throws error “SECONDS cannot be resolved to a variable”.I completely copied this lessons code, i its throwing this error.plz do explain
Just put static to java.util.concurrent.TimeUnit.*; I used to have the same error.
hello derek, i am getting error on line no 30,32,34 . the eclipse throws error “SECONDS cannot be resolved to a variable”.I completely copied this lessons code, i its throwing this error.plz do explain
Derek instead of library here i used TIMEUNIT.SECONDS directly as argument so i got perfect result.
I’m confused on why java.util.concurrent.TimeUnit.* didn’t work? That is odd. Thank you for pointing that out
So this pretty much explains the concept of multi threading? Or is that something else? I would think multi-threading involves running the threads at the same time not scheduled threads.
More threads than cores / cpus will slow things down due to the overhead of switches with multi-threading
Exception in thread “main” java.lang.Error: Unresolved compilation problems:
SECONDS cannot be resolved to a variable
SECONDS cannot be resolved to a variable
SECONDS cannot be resolved to a variable
at LessonEighteen.addThreadsToPool(LessonEighteen.java:15)
at LessonEighteen.main(LessonEighteen.java:10)
I replace SECONDS with timeUnit.SECONDS
I’m glad you got it working. Sorry I couldn’t get to you quicker
Exception in thread βmainβ java.lang.Error: Unresolved compilation problems:
You should write TimeUnit.SECONDS, that`s enum in java except using only SECONDS
Hi, your video tutorials are awesome!! Thank you for this great vidoes.
I have a question. Why we used try block in addThreadToPool() method?
try{
Thread.sleep(20000);
}
catch(InterruptedException e){}
Best Regard,
Burak
That is there to solve issues that an interrupt may cause.
Is there a limit to how many threads can be started? Is there any type of architecture dependency for threads, like does it have to be multi-CPU etc for the threads to run simultaneously?
The JVM has an upper limit to the number of threads, but it is in the 10s of thousands. For each new thread you create you will take a performance hit.