Java Thread Programming (Part 7)
Can we create as many Java threads as we want? I will try to come up with an answer via an exercise, so bear with me!
Can we create as many Java threads as we want? I will try to come up with an answer via an exercise, so bear with me!
Have you ever wondered what is the purpose of the “wait()”, “notify()”, “notifyAll()” methods that come with each Java object?
Optional is a mystery box, a wrapping paper: it may or may not contain the value. When we specify that in a method signature, we assume that the box might be empty.
In this article, we will discuss another situation called “race conditions” and how we can resolve it.
We need to be very careful when using the “volatile” keyword, and we should use it only where it’s required, and definitely not everywhere.
Tip: We can only ask the Java thread to execute a piece of code, but we cannot guarantee the execution order of multiple threads!
Let’s see an example of where we can use Threads. Let’s assume we are building a web server that returns the most used words in a website.
We write code in a file line by line, and then it gets executed. To be able to execute a piece of code requires an execution environment. In Java, a thread is an executing environment. If a program has only one executing environment, then we call this program a single-threaded program.
Did you know that you can save up to 25% of your heap memory and your Cloud bills without any effort? Well, it’s true.
Many exciting features have been added to the latest releases of Java recently and I’m going to cover one that is often overlooked in this article.