Java has two units of execution—process and thread. A process usually represents the whole JVM, although an application can create another process using java.lang.ProcessBuilder. But, since the multi-process case is outside the scope of this book, we will focus on the second unit of execution, that is, a thread, which is similar to a process but less isolated from other threads and requires fewer resources for execution.
A process can have many threads running and at least one thread called the main thread—the one that starts the application—which we use it in every example. Threads can share resources, including memory and open files, which allows for better efficiency. But it comes with a price of higher risk of unintended mutual interference and even blocking of the execution. That is where programming skills and an understanding of...