Home > Store

High-Performance Java Platform Computing: Multithreaded and Networked Programming

Register your product to gain access to bonus material or receive a coupon.

High-Performance Java Platform Computing: Multithreaded and Networked Programming

Book

  • This product currently is not for sale.
Not for Sale

About

Features

Description

  • Copyright 2001
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-016164-0
  • ISBN-13: 978-0-13-016164-2

  • The clear, practical guide to Java threads and concurrency
  • Proven design patterns and extensive code library
  • Expert techniques for optimizing networked/distributed applications
  • Avoiding deadlocks, race conditions, and synchronization problems

Threading, concurrency, and beyond: Your crystal-clear Java performance guide and code library!

Threading and concurrency are crucial to building high-performance Java applications — but they have a reputation for complexity. High-Performance Java Computing thoroughly demystifies them, helping developers leverage threading and concurrency to solve a wide variety of performance problems — especially in networked, distributed applications. This book delivers practical solutions, proven design patterns, and a rigorously tested code library: everything you need to build optimized Java software for technical, business, and e-Commerce applications. Coverage includes:

  • Java 2 Threads classes: daemon threads, thread control, scheduling, and more
  • Solving the key problems of parallelism: deadlocks, race conditions, and synchronization
  • Advanced techniques for optimizing concurrent code
  • Java monitors, parallelizing loops, and parallel execution of subroutines in shared memory
  • New design patterns for distributed application development

There's never been a more accessible, practical guide to Java multi-threading, concurrency, and other high-performance techniques. When performance really matters, turn to High-Performance Java Computing — and find the solution you're searching for!

Sample Content

Downloadable Sample Chapter

Click here for a sample chapter for this book: 0130161640.pdf

Table of Contents



1. Foundations.

The von Neumann Machine. Flynn's Taxonomy. Control-Memory Taxonomy. Speedup and Efficiency. Amdahl's Law. Scalability. Problems of Parallelism. Grain Size. Starvation. Deadlock. Flooding and Throttling. Layout. Latency. Scheduling. Programming Techniques. Chapter Wrap-up. Exercises.



2. Threads.

Why Is Multithreading Useful? Overview of the Java Threads Classes. Thread: The Class Responsible for Thread Creation and Execution. Runnable: Making Threads Without Extending the Thread Class. Hello World: A First Example of Multithreading. Implementing Interfaces and Extending Classes: What's the Deal? Concepts. A Little Bit of History. Some Definitions. Multiprogramming vs Multitasking. Concurrency vs Parallelism vs Distribution. Threads vs Processes. Kernel-level vs User-level Threads. Quick Tour of Java Threads Functions. Construction. Daemon Threads. Thread Control. Very Useful Static Methods. Thread Synchronization. Cooperative Multitasking. Prioritized Scheduling. Miscellaneous Status Methods. Methods Not Covered Here. Exercises.



3. Race Conditions and Mutual Exclusion.

Know Your Enemy! Race Conditions. Egoist: A First Study in Race Conditions. A Word on Priorities. What Is a Race Condition? Race0 Class. Critical Sections and Object Locking. Race1 Class-Fixing Race0 with Synchronization. Conditions. Motivating the Need for Conditions. Key Object Methods Needed to Work with Conditions in Java. File Copying: A Producer-Consumer Example. Locks-Binary Semaphores: An Example of Using Conditions. Race2: Reworked Race1 Using Locks. Classic Synchronization Mechanisms. Counting Semaphore. Barrier. Futures. Deadlock. What Is Deadlock? How to Know When Deadlock Has Hit You? Four Conditions of Deadlock. A Classic Example: Dining Philosophers. Chapter Wrap-up. Exercises.



4. Monitors.

Real Monitors and Java Monitors. Class Monitor in the Thread Package. Monitor's Methods. Interface MonitorCondition's Methods. Interface MonitorLock. Examples using Monitor Objects. SimpleFuture. SharedTableOfQueues. Implementation of Monitor, Condition, and MonitorLock. Monitor Entry and Exit. Monitor.Condition. Monitor.Lock. The Multiple Reader-Writer Monitors. Policies. Entering and Leaving the Critical Sections. The Single-Reader-Writer Monitor. The Readers-Preferred Monitor. The Writers-Preferred Monitor. The Alternating Readers-Writers Monitor. The Take-a-Number Monitor. Chapter Wrap-up. Exercises.



5. Parallel Execution of Subroutines in Shared Memory.

Creating and Joining. Example: Trapezoidal Numeric Integration. RunQueue. RunQueue Methods. RunQueue Implementation. Recursive Shell Sort: RunQueues and SimpleFutures. Accumulator. Accumulator Operations. Patterns of Use of Accumulators. Using Accumulators. Numeric Integration. TerminationGroup. Combinatorial Search. The 0-1 Knapsack Problem. Parallel Depth-first Search for the Knapsack Problem. Knapsack2. PriorityRunQueue. Branch-and-Bound with Priority Run Queues. Branch and Bound for 0-1 Knapsack. A Purer Branch-and-Bound 0-1 Knapsack. Chapter Wrap-up. Exercises.



6. Parallelizing Loops.

Chore Graphs. Gathering Chores into Threads. Example: Warshall's Algorithm. Static Scheduling. Dynamic Scheduling. Example: Longest Common Subsequence. Example: Shell Sort. Chapter Wrap-up. Exercises.



7. Chores.

The RunDelayed Interface. Futures. FutureFactory. Chore-programming Techniques. Job Jars. Chore Graphs. Macro Dataflow. Flow of Control. Macro Dataflow Examples: Vector Addition. Continuations to Separate Operand Fetch from Operation. Static Dataflow Style and Storing Operands in Instructions. Fetching in Continuations. Chore examples: Warshall's Algorithm. WarshallDF1 and Warshall's Algorithm in Dataflow. WarshallC1 through WarshallC3: Chores, But Not Dataflow. Chapter Wrap-up. Exercises.



8. Thread and Chore Synchronization.

TerminationGroup. Barrier. BarrierFactory. AccumulatorFactory. Parallel Quicksort. Shell Sort. Chapter Wrap-up.



9. Shared Tables of Queues.

Shared Tables of Queues. Methods. Implementing Synchronizations Using a Shared Table of Queues. Indexed Keys. Implementing More Synchronizations and Shared Structures. Reactive Objects. Communicating through a Shared Table of Queues. Future Queues. Methods. Implementation of FutureQueue. Example of FutureQueue: The Queued Readers-Writers Monitor. Future Tables. Chapter Wrap-up. Exercises.



10. Streams Essentials.

The Streams Abstraction. Building Your Own Stream. Caesar Cipher: Very Basic Encryption. Chapter Wrap-up. Exercises.



11. Networking.

Exploring the Client Side. Services: The Internet Story. Destination Sendmail. Java Networking: Socket and InetAddress. Where Are the Services? A Kind and Gentle Introduction to the Server Side. Iterative Servers. Simple Messaging Architecture. The Message Class. DateService and DateClient SMA Style. Chapter Wrap-Up. Exercises.



12. Coordination.

Generic Mailbox Invocations. GMI: Goals and Design Overview. Callable: An Interface for Accepting Communication. CallMessage: An Abstract Class for Marshalling and Unmarshalling! RemoteCallServer. RemoteCallServerDispatcher. MemoServer. MemoClient. Vector Inner Product. Trapezoidal Integration. Warshall's Algorithm. Chapter Wrap-up. Exercises.



Index.

Preface

Preface

This is a book about programming high-performance multithreaded applications using the Java language.

Multithreading and multiprogramming, long heralded as useful ideas in the computing literature, have been the focus of numerous textbooks on operating systems, parallel and distributed computing, and, most, recently Java. Yet a key question remains unanswered: Why would one really use threads in the first place?

Our book attacks this question from the bottom up and the top down. Beginning with the bottom-up discussion, threads have been created with the primary goal of improving performance of software applications. At a low level, a thread is much like a process, but differs from processes in one key respect: resource consumption. This is because threads, unlike processes, share common code and data, thus having a lower cost of creation and context-switching overhead.

On the other hand, the low-level focus on threads-the mechanism-has much to do with why threads have not achieved widespread usage in applications. Threads do allow great advances in performance to be made, but not without some up-front program structuring. The fact that all threads share data structures can in many cases lead to poor performance, due to synchronization costs.

To answer the question posed earlier, we believe multithreading exists primarily to allow performance gains to be realized, particularly on scalable hardware platforms, such as parallel supercomputers, workstation clusters, and symmetric multiprocessor (SMP) systems. Our book emphasizes programming techniques and packages for high-end computing (often called the "server side" in the business world). We are concerned with using the power available on multiprocessor computers and computer networks to perform computations rapidly.

This book was conceived as a natural follow-up to a successful series of short courses we offered at the Illinois Institute of Technology and elsewhere to working professionals and graduate students alike. Additionally, between us we have approximately two decades of relevant teaching and research experience in the fields of high-performance computing, object-oriented systems, programming languages, and operating systems.

Our research in high-performance computing and languages has always focused on facilitating the development of concurrent, parallel, and distributed software, going back as far as 1988, when we first began working together on the Message Driven Computing (MDC) environment. We have developed a number of working programming languages and libraries to support such software development. All of the work we did in the past, however, was done in the C, Icon, and C++ programming languages. For this book, we have reworked many of our ideas into a form more suitable for the practicing software engineer, while fully exploiting the power of a true object language such as Java.

With its built-in support for concurrency via a monitorlike abstraction, Java makes concurrent programming easier for programmers than languages such as C and C++. We will discuss how monitors are adequate for solving many problems in concurrency, particularly the so-called classical synchronization problems, which have been well documented in operating-systems textbooks. As more complex libraries and software systems are developed, the evidence gathered supports the proposition that monitors, much like other low-level mechanisms for synchronization, break down. Monitors, despite being a higher-level mechanism for supporting concurrency, present the same problems as found in "less sophisticated" environments such as C and C++ (where low-level threads libraries, such as pthreads and Win32 threads, are used). We refer in the text to these problems (race conditions and deadlocks) as enemies. We present stategies for dealing with these enemies and a number of higher-level frameworks that enable the programmer to worry less often about them.

Java is one of the great programming languages of our time. Like many of the great programming languages, a company was behind its development, adoption, and popularity. The sensational marketing blitz was enough to make many of us think that all of the work on languages was now complete, so we could start packing our bags and look for other work. Now that the dust has settled, it is clear that Java does occupy an important space in the marketplace; however, there is a great deal of potential for exploring other programming languages and techniques. The environments in which Java is being considered will require at least a subset of the ideas presented in this book: network appliances, server-side computing, workstation clustering, and parallel systems, to name a few. In this book, our aim is to give the reader some insight into what Java does and does not provide, in terms of support for concurrency. What Java does not provide, we do provide with a working library of Java code that allows the programmer to "operate at a higher-level" (to borrow a phrase from IBM marketing from the OS/2 days).

This book, like all books, does not exist in a vacuum. There are a number of competing books, some of which are appearing in new editions during the next year. We believe our book will be the first of its kind in terms of multithreading and its application to real-world programming. It also provides the following benefits and features:

  1. It presents a human-understandable explanation of multithreading, its implementation, and how it works in Java.
  2. It helps the programmer to understand the very real problems encountered in concurrent systems, focused on race conditions, deadlock, and problems encountered when introducing parallelism and distribution. This particular aspect of our book brings to life the chapters on concurrency presented in "abstract" OS textbooks, wherein working code examples are seldom, if ever, provided.
  3. It helps the programmer to understand the classic synchronization problems, which have suddenly been placed in the spotlight as more and more code is (incorrectly) being written to exploit concurrency.
  4. It introduces high-level approaches to shared- and distributed-memory multithreading. This section will be of great interest to those who want to develop multithreaded applications but prefer to work at a higher level.
  5. It shows how to extend the threads concept to the network. It shows how to extend the threads model beyond the single Java Virtual Machine (JVM) to a network of JVMs.

We hope you enjoy this book. It has been written to address the needs of a broad audience. There is introductory, intermediate, and advanced material. The book is designed to be progressive and can be used either as a reference or as a companion to a variety of courses. Exercises are provided at the end of each chapter to reinforce the principles.

Speaking of Code

Code for the Tools of Computing thread package is available through our company Web site at http://www.toolsofcomputing.com. You will find links to it on the book sub-Web at http://www.toolsofcomputing.com/JavaThreads. We also provide a number of other useful, free packages via the sub-Web.

The example programs are working examples. We have run all of them. We hope the printed versions are as error free as possible; however, mistakes do occur and bugs are found. We actually use our code for development and will regularly update the site to include the latest code. All of the code is freely available under a GNU LGPL-style license.

The algorithm animations available include parallel sorting algorithms and simulations of multiple readers and writers synchronizing with the monitors shown in "The Multiple Reader-Writer Monitors" on page 110. These animations are applets.

We will maintain an errata forum to report errors and corrections found after publication.

Animations

The Multiple Readers-Writers Simulations Color Codes

The simulations include an array of buttons that indicate the states of the threads accessing the shared structure. The colors of the buttons the threads states:

Red Writing
Blue Reading
Magenta Waiting to write
Cyan Waiting to read
White Resting between reads or writes
Gray Has finished its iterations.

How to Change the Parameters

You can change the parameters in the multiple readers-writers simulations.

You may choose to have a thread choose randomly each time whether to read or write (the default) or to be always be a reader or always a writer. The "% reads" and "# readers" radio buttons choose which option. You use the corresponding text fields to specify the percent probability of reading or the number of threads that are readers, respectively.

To change any number, edit the field and then type ENTER. The new value will not be stored until ENTER is pressed.

You can choose whether the actual read, write, and rest times are constants or whether they are generated from negative exponential distributions. You are able to specify the times' constant or mean values. If you change the mean read, write, or rest times, you should probably not go much below 200ms; smaller values don't give Java enough time to refresh the display. Constant times give simulations that are easier to understand.

You can change any of the values in the left column. The bottom four text fields on the right are output fields. Although you can change the lower four fields yourself, making manual changes won't have any influence on the simulation.

Experiments

There are several charts in this book showing the performance of parallel algorithms. These charts report experimental runs on an intel dual-processor system running Solaris located in the Java High Performance Computing laboratory at DePaul University in Chicago. The Java system has kernel threads, which allow both processors to execute threads in the same program simultaneously.

The experiments were run from scripts that executed, in random order, the algorithms, problem sizes, and number of threads. This was to avoid potential errors that could occur if the system had different loads at different times. If we did not randomize the order, we might not be seeing the effects of the parameters, but rather of system load. The runs in the scripts were separated with sleep calls in order to prevent Unix from "nicing" our priority down because our process is compute-bound.

Each algorithm-problem size-number of threads combination was run 32 times to allow the use of large-sample statistics.

In some of the summary charts, where we combine several runs, we did not run the experiments again with the same care for randomizing the runs; therefore, these comparisons may be viewed with suspicion, because they may show effects of differing system loads.

Running the Exercises

To run programs for most of the exercises, you will need a multiprocessor and a kernel-threads version of Java (at least if you want to see any kind of performance improvement). Intel dual-processor systems have become inexpensive. Solaris and Linux are reasonable operating systems, as are Windows NT and successors.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020