Hello! My name is Will Tollefson, and I'm a software engineer who enjoys learning and teaching others! I've been programming for over a decade now; the field of computer programming is continuously evolving, requiring even the most experienced programmers to acquire new skills. Whether its website design, artificial intelligence, or mobile app development, knowledge of computer programming opens the door to jobs in the tech sector, new hobbies, or impressing your grandma with your savvy computer skills! I've created this channel for beginning to expert programmers alike as a resource for learning and staying on the edge of programming.
Great into tutorial! However, I wish you went a little more into detail at the end. For instance, how do we find which threads the thread numbers are referring to? Also, how do we know which objects the threads are locked? You got answers like "0x2fc," but how do we find which variable that is referring to?
Thanks for the question! The short answer is that the stack traces in the thread dump will usually tell you enough for a simpler example like this, but I do hear your point about more advanced debugging. In this particular example the trace tells you the line number its blocking on waiting for monitor entry and it tells which thread its waiting on. I've thought about making a video (or a series) on different debugging techniques with threading issues being a top contender. Is that something you'd like to see?
@@willtollefson Yes; I would love a series about that. I have been studying computer science for two years now, but my textbook and classes never talked about the debugger. It's actually really embarrassing that I know nothing really about it😂😂
@audiomac sounds good - I totally get it and I've heard that from a lot of folks. It seems like teaching debugging isn't always a priority which is odd to me since that's a decent portion of what devs do in industry. I'll see about putting out some more debugging videos in the future. Thanks!
There are parts that are harder than others, yes. I found it helpful to take a higher level look at the stream API before taking a deeper dive into a component of it. If there’s anything I can help explain better, feel free to reply on this thread!
Hii Will, Thanks for making this video. I have a quick question here , it may seem little bit silly to you. why in 12:02 section of the video, we are trying to use a object instance of Thread class to call print status method. Pls explain if possible. and Thanks again!
Thanks for the question! I glossed over that part in the video. The reason it’s doing that is because there needs to be a way to look at the status of the 1000 requests asynchronously and the way I implemented it was a status thread that starts executing after you construct the Server object. It could have instead been a getter that gets called periodically after the requests start submitting, but with the code as written if it weren’t done in a separate thread, the executor block would never be hit because the main class would have been blocked after Server constructor if that private method was called from in the constructor with the same thread. Hope this helps!
Do you want to know about how garbage collection works in Java in general, or specifically how it would pertain to something like a template expression?
THANK YOU!!! Your video helped me understand the difference between the two after a Udemy course failed doing so. Granted, I had to pause a few times and look up more stuff that I forgot already, but now ... 🤯 And as a lover of keyboard shortcuts, the sout > System.out.println() made me incredibly happy.
A checked exception doesn’t necessarily mean an error can be detected at compile time or not (otherwise the compiler would just flag it right away). It just means that you have to provide explicit error handling code. Both checked and unchecked exceptions represent errors that can occur at runtime. The merits of checked exceptions are debatable, but among other checked exceptions, this one makes sense to me because there is reasonable likelihood of code hitting a case like this and you should have specific handling code available for it. Hopefully that helps clarify it a bit!
You can use another while loop to do that. For example if you want to keep the number range the same each time but select a different random number for each iteration, you could add a while loop around line 12.
Thanks for the comment and suggestion! Admittedly I sometimes do my filming late at night because there often aren’t enough hours in the day. I’ll do my best to get better at this 🙂
Its cool feature definatly I will use but there are people in my company who would revert my code and use jackson instead to create json Don't know how to deal with foolish people specially when the have power and evil intension against you
Sometimes adopting new ways of doing things takes time. In this situation they aren’t adding the feature in its current state to the language and will probably preview an updated version in a later JDK. Hopefully you can reason with the other folks at your company one way or the other. I’ve often found logical reasoning works well for programmers that program computer logic everyday 🙂
@@willtollefson Thanks but sometimes you find yourself in a place where stubbornness prevails over rationality and logical reasoning. But it good these days we have people like you who help others to stay up to date with their videos and other content
I'll be sure to get to this when I can! I've been taking a short break recently while I have a very little one at home, but I hope to get back into a more regular posting schedule in the future!
Yeah, it was a good concept, but unfortunately had some design flaws that they are working out now. Hopefully it will have a come back in another preview coming up
If I’m understanding your question correctly, you would need to setup a public IP address with this method that is reachable to other networks and as long as you had network connectivity and the same socket protocol, you should generally be able to communicate.
@@willtollefson Hey, I strongly agree with Mat. I don't write comments either, but finally now I understand lamdas... It's strange that you have so few viewers with such a great content. Thanks a lot!
Since its an object reference, the local variable value (e.g. the reference value) is cached, but the object data itself remains on the heap, so as long as you don't change the object reference, you'll still reference the same heap data across all of the threads. This is why its preferred to mark the object reference as immutable because that helps give you guarantees about the concurrent protection of the value. It doesn't, however, guarantee concurrent modification protection of the underlying object, which is why we're using AtomicInteger.
@@willtollefson thanks, I'm surprised because if I understand correctly then objects are always read from the heap and the cost is significantly higher.
Great point. The JLS (to my knowledge) doesn’t specify any sort of read optimizations in this type of situation. Something like that could probably be implemented per JVM if it can detect situations where a more efficient read can happen on an object reference (and I’m sure it does)
Thanks for the comment! Here are some videos I've done on those topics: Volatile and atomic: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-31s_DzrkqZc.html Synchronized: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-FpNRXz696ZY.html I've also done a few videos talking about runnables in general, virtual threads, and structured concurrency. If those don't scratch the itch, let me know and I can do a video on a specific threading topic.
Thank you! Really simple it seems, haven't had to use one yet until now for my personal projects, and it seems like the Semaphores meet my needs easily. I was worried that I would've needed something more complex. Did you ever get around to making that lock video? I am going to be watching some of your other concurrency videos soon though to see what the other solutions look like.
That lock video is on my short list right now of future videos to make. There are multiple flavors of locks - if there's a particular thing you want me to cover in that video, let me know!
3 месяца назад
Great stuff man! I really find your explanations very useful. Thanks for sharing
Personal preference I suppose 🙂 I know folks who use it every chance they get and others that wish it was never added to the language. What are your thoughts on it? I agree with a lot of what is stated here: openjdk.org/projects/amber/guides/lvti-style-guide
It takes 1.3 seconds on average to run 100,000 concurrent "1 second sleep" tasks in Go. This is 4 times faster than in your example. Is it expected? I didn't run Java version on my machine (I don't have it), but my laptop is not a super computer by any means. And just for the fun of it, I ran with 1M concurrent tasks and it took 3.1 seconds on average. And then, for even more fun, I ran it with 10M tasks; finally it was slower than 5 seconds, 11 seconds to be exact. I wonder if you can try your code with 1M tasks and share your results.
Thanks for the comment! When I run 1M tasks on my machine with the Java version, I'm getting 10-11 seconds. When I run similar Go code on my machine I'm getting around 5 seconds. Without deep diving the compiled byte code and go binary to really figure out the performance difference, I have a few upfront guesses: 1. Java warm up could be playing a small role here due to lazy initialization for things like the classloader and virtual threads mapping to platform threads 2. Java and Go have different default behavior for the number of routines that can be executed in parallel and the number of OS threads available to the runtime for scheduling. 3. Goroutines are optimized to have a small stack size at the beginning of execution and then expand as needed. I'm wondering if stack allocation for Java virtual threads is more expensive in this case. Both are still MUCH better in this example than the previous Java thread model though :)