The Java Thread model
The Java run-time system depends on threads for many things, and' all the class libraries are-designed with multithreading in mind. In fact, Java uses threads to enable the entire environment to be asynchronous. This helps reduce inefficiency by preventing the waste of Cl'U cycles. . The value of a multithreaded environment is best understood in contrast to its counterpart. Single-threaded systems use an approach called an loop with Rolling. In this model, a single thread of control runs in an infinite loop, polling a single event . queue to decide what to do next. Once this polling mechanism returns with, say, a signal that a network file is ready to be read, then the event loop dispatches control to the appropriate event handler. Until this event handler returns, nothing else can happen in the system. This wastes CPU time.
It can also result in one part of a program dominating the 'system and preventing any other events from being processed. In general, in a single-threaded environment, when a thread blocks .(that is, suspends execution) because it is wailing for some resource, the entire program stops running. The benefit of Java's multithreading is that the main loop/polling mechanism is . eliminated. One thread can pause without stopping other parts of your program. For example, the idle time created when a thread reads data from a network or waits for user input can be-utilized elsewhere. Multithreading allows animation loops to sleep for a second between each frame without causing the whole system to pause. When a thread blocks in ex Java program, only the single thread that is blocked pauses: All other threads continue to run. . . Threats exist in several states. A thread can be running, It can be ready to run as soon as it gets CPU time. A running thread can be suspended, which temporarily suspends its activity. A suspended thread can then be resumed, allowing it to pick up where it left off. A thread can be blocked when wailing for a resource. At any time, a thread can be terminated, ~which halts its execution immediately. Once terminated, a thread cannot be resumed.