Web hosting account - 840 Multithreading Chapter 15 book, moving the book
840 Multithreading Chapter 15 book, moving the book you are reading closer so you can see it, pushing books you are not reading aside, and amidst all this chaos, trying to comprehend the content of the books! Performance Tip 15.2 A problem with single-threaded applications is that lengthy activities must complete before other activities can begin. In a multithreaded application, threads can share a processor (or set of processors), so that multiple tasks are performed in parallel. Although Java is perhaps the world s most portable programming language, certain portions of the language are nevertheless platform dependent. In particular, there are differences among the first three Java platforms implemented, namely the Solaris implementation and the Win32 implementations (i.e., Windows-based implementations for Windows 95 and Windows NT). The Solaris Java platform runs a thread of a given priority to completion or until a higher priority thread becomes ready. At that point preemption occurs (i.e., the processor is given to the higher priority thread while the previously running thread must wait). In the 32-bit Java implementations for Windows 95 and Windows NT, threads are timesliced. This means that each thread is given a limited amount of time (called a time quantum) to execute on a processor, and when that time expires the thread is made to wait while all other threads of equal priority get their chances to use their quantum in round- robin fashion. Then the original thread resumes execution. Thus, on Windows 95 and Windows NT, a running thread can be preempted by a thread of equal priority; whereas, on the Solaris implementation, a running Java thread can only be preempted by a higher priority thread. Future Solaris Java systems are expected to perform timeslicing as well. Portability Tip 15.1 Java multithreading is platform dependent. Thus, a multithreaded application could behave differently on different Java implementations. 15.2 Class Thread: An Overview of the Thread Methods In this section, we overview the various thread-related methods in the Java API. We use many of these methods in live-code examples throughout the chapter. The reader should refer to the Java API directly for more details on using each method, especially the exceptions thrown by each method. Class Thread (package java.lang) has several constructors. The constructor public Thread( String threadName ) constructs a Thread object whose name is threadName. The constructor public Thread() constructs a Thread whose name is “Thread-” concatenated with a number, like Thread-1, Thread-2, and so on. The code that does the real work of a thread is placed in its run method. The run method can be overridden in a subclass of Thread or it may be implemented in a Runnable object; Runnable is an important Java interface that we study in Section 15.10. A program launches a thread s execution by calling the thread s start method, which, in turn, calls method run. After start launches the thread, start returns to its
Check Tomcat Web Hosting services for best quality webspace to host your web application.