|
|
|
|
|||
|
The SCJP Handbook |
One of the literal meanings of thread is a sequence. In the context of computer programming, ‘thread’ means sequence of execution. The concept of threads originated in operating systems. CPU is the workhorse of operating systems. To use it as efficiently as possible, threads were introduced. Each job-to-be-done is abstracted as a thread. Since there are multiple jobs-to-be-done in operating systems, there are multiple threads of execution. The multithreaded operating systems can schedule the threads in such a way that despite one CPU, it can run multiple threads. For instance, the threads may take turns to use the CPU. Therefore, you get an illusion that multiple CPUs are running because multiple jobs are getting done simultaneously.
A thread in Java is Java's effort to use the same theory while executing Java programs. A single JVM can execute one set of instructions at a time. However, Java threads make it possible to execute multiple jobs in single JVM. This is an illusion just like the operating systems. Here you will feel that single JVM is executing multiple Java programs. Java provides you with features for creating and managing multiple threads-of-execution. When you are developing a complex application that requires doing multiple jobs in the most efficient fashion, you need to know about threads and how they can help in using the valuable resources as efficiently as possible.
The certification exam’s threads objective requires you to know what the Java threads are, how to define one and how to control them. You also need to know how the threads can communicate with each other to use the JVM and its resources efficiently. Specifically this chapter covers the entire seventh SCJP objective.