Few weeks back i started reading Java™ How to Program, Sixth Edition By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.
Nice book written By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.
I wanted to share few quotations found the book from the 23rd chapter.
1) Computers perform operations concurrently, such as compiling programs, sending files to a printer and receiving electronic mail messages over a network.
2) Programming languages generally provide a set of control statements that only enable programmers to perform one action at a time.
3) Historically, concurrency has been implemented as operating-system primitives available only to experienced systems programmers.
4) Java makes concurrency available to the applications programmer. The programmer specifies that applications contain threads of executioneach thread designating a portion of a program that may execute concurrently with other threads. This capability is called multithreading.
5) A new thread begins its life cycle in the new state. It remains in the new state until the program starts the thread, which places the thread in the runnable state.
6) A runnable thread enters the terminated state when it completes its task or otherwise terminates.
7) Sometimes a thread transitions to the waiting state while it waits for another thread to perform a task. Once in this state, a thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.
8) A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires. A thread can transition to the timed waiting state if it provides an optional wait interval when it is waiting for another thread to perform a task. Such a thread will return to the runnable state when it is signaled by another thread or when the timed interval expireswhichever comes first. Another way to place a thread in the timed waiting state is to put the thread to sleep.
9) At the operating system level, the runnable state actually encompasses two separate states. When a thread first transitions to the runnable state from the new state, the thread is in the ready state. A ready thread enters the running state (i.e., begins executing) when the operating system assigns the thread to a processor. When the thread's quantum expires, the thread returns to the ready state, and the operating system assigns to the processor another thread.
10) Every Java thread has a priority in the range between MIN_PRIORITY (1) and MAX_PRIORITY (10). By default, each thread is given priority NORM_PRIORITY (5).
11) Most Java platforms support timeslicing. Without timeslicing, each thread in a set of equal-priority threads runs to completion before other equal priority threads get a chance to execute. With timeslicing, each thread receives a brief burst of processor time, or quantum, during which the thread can execute. When the quantum expires, even if the thread has not finished executing, the processor is taken away from it and given to the next thread of equal priority, if one is available.
12) The thread scheduler determines which thread runs next. One simple implementation will keep the highest-priority thread running at all times. If there is more than one highest-priority thread, the scheduler ensures that all such threads execute for a quantum each in round-robin fashion.
13) Multithreading in Java is accomplished by implementing the Runnable interface, which declares a single method named run.
14) Runnables are executed using a class that implements the Executor interface, which declares a single method named execute.
15) Interface ExecutorService is a subinterface of Executor that declares several methods for managing the life cycle of the Executor. An object that implements the ExecutorService interface can be created using static methods declared in class Executors.
16) ExecutorService method shutdown ends each thread in an ExecutorService as soon as it finishes executing its Runnable.
17) When multiple threads share an object, indeterminate results may occur unless the shared object is synchronization properly. Mutual exclusion allows the programmer to perform such thread synchronization.
18) Once a Lock has been obtained by a thread (by calling the lock method), the Lock object will not allow another thread to obtain the lock until the first thread releases the Lock (by calling the unlock method). When a thread calls method unlock, the lock on the object is released and the highest-priority waiting thread attempting to lock the object proceeds.
19) Once a thread obtains the lock on an object, if the thread determines that it cannot continue with its task until some condition is satisfied, the thread can wait on a condition variable, thus removing it from contention for the processor and releasing the lock on the object. Condition variables are created by calling Lock method newCondition, which returns a Condition object.
20) A thread can call method await on a Condition object to release the associated Lock and place that thread in the waiting state while other threads try to obtain the Lock. When another thread satisfies the condition on which the first thread is waiting, that thread can call Condition method signal to allow the waiting thread to transition to the runnable state again. If a thread calls Condition method signalAll, then all the threads waiting for the lock become eligible to reacquire the lock. Only one of those threads can obtain the lock on the object at a timeother threads that attempt to acquire the same lock will have to wait until the lock becomes available again.
21) In a producer/consumer relationship, the producer portion of an application generates data and stores it in a shared object, and the consumer portion of an application reads data from the shared object. In a multithreaded producer/consumer relationship, a producer thread generates data and places it in a shared object called a buffer. A consumer thread reads data from the buffer.
22) To minimize the amount of waiting time for threads that share resources and operate at the same average speeds, use a circular buffer that provides extra buffer space into which the producer can place values and from which the consumer can retrieve those values.
23) The BlockingQueue interface declares methods put and take, which are the blocking equivalents of Queue methods offer and remove, respectively. This means that method put will place an element at the end of the BlockingQueue, waiting if the queue is full. Method take will remove an element from the head of the BlockingQueue, waiting if the queue is empty. Class ArrayBlockingQueue implements the BlockingQueue interface using an array. This makes the data structure fixed size, meaning that it will not expand to accommodate extra elements.
24) Swing components are not thread safeif multiple threads manipulate a Swing GUI component, the results may not be correct. All interactions with Swing GUI components should be performed in the event-dispatch thread. Class SwingUtilities provides static method invokeLater to help with this process. Method invokeLater receives as its argument an object that implements interface Runnable and performs the GUI updates.
25) The Callable interface declares a single method named call which allows the user to return a value or throw a checked exception. The ExecutorService interface provides method submit which will execute a Callable passed in as its argument. The submit method returns an object of type Future which is an interface that represents the executing Callable. The Future interface declares method get to return the result of the Callable and provides other methods to manage the execution of the Callable.
26) An object's monitor allows one thread at a time to execute inside a synchronized statement on that object.
27) When a runnable thread must wait to enter a synchronized statement, it transitions to the blocked state. When the blocked thread enters the synchronized statement, it transitions to the runnable state.
28) Java also allows synchronized methods which is equivalent to a synchronized statement that encloses the entire body of the method.
29) Once a thread obtains the monitor lock on an object, if the thread determines that it cannot continue with its task on that object until some condition is satisfied, the thread can call Object method wait, releasing the monitor lock on the object.
30) When a thread executing a synchronized statement completes or satisfies the condition on which another thread may be waiting, the thread can call Object method notify to allow a waiting thread to transition to the blocked state again.
31) If a thread calls notifyAll, then all threads waiting for the monitor lock become eligible to reacquire the lock (that is, they all transition to the blocked state).
About the Authors
Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.
Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of the MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered Java, C, C++, Internet and World Wide Web courses to industry clients, including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, Compaq, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, Open Environment Corporation, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the most experienced Java corporate trainers having taught about 100 professional Java training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.
Wednesday, 4 March 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment