Multithreaded Programming with Java Technology

Multithreaded Programming with Java Technology

by Bil Lewis, Daniel J. Berg, Sun Microsystems Press
     
 

1700G-6

  • The ultimate guide to multithreading with Java technology!
  • Powerful techniques for enhancing application performance
  • Multithreaded program design for network and Internet applications
  • Extensive code examples throughout

Multithreading gives developers using the Java 2 platform a powerful tool for

Overview

1700G-6

  • The ultimate guide to multithreading with Java technology!
  • Powerful techniques for enhancing application performance
  • Multithreaded program design for network and Internet applications
  • Extensive code examples throughout

Multithreading gives developers using the Java 2 platform a powerful tool for dramatically improving the responsiveness and performance of their programs on any platform, even those without inherent multithreading support. Multithreaded Programming with Java Technology is the first complete guide to multithreaded development with the Java 2 platform. Multithreading experts Bil Lewis and Daniel J. Berg cover the underlying structures upon which threads are built; thread construction; and thread lifecycles, including birth, life, death, and cancellation. Next, using extensive code examples, they cover everything developers need to know to make the most of multithreading, including:

  • Thread scheduling models and synchronization-with solutions for complex, real-world synchronization problems
  • Multithreaded program design for networked and Internet applications
  • Thread-specific data: use and implementation
  • Leveraging OS libraries to make Java-based multithreading more effective
  • Optimizing thread performance and designing for SMP hardware

Powerful techniques and comprehensive example code for improving Java-based application performance with multithreading!

Product Details

ISBN-13:
9780130170071
Publisher:
Prentice Hall
Publication date:
12/17/1999
Series:
Sun Microsystems Press Series
Pages:
461
Product dimensions:
7.20(w) x 9.20(h) x 1.10(d)

Read an Excerpt

PREFACE:

Preface

Today, there are three primary sets of multithreading (MT) libraries: the POSIX threads library, the Win32 threads library (both native), and Java. Although the APIs and implementations differ significantly, the fundamental concepts are the same. The ideas in this book are valid for all three; the details of the APIs differ.

All the specific discussion in this book focuses on the Java multithreading model, with comparisons to POSIX and Win32 throughout. Java threads are always implemented upon a low—level library which does the real work. Hence Java on UNIX is generally based on POSIX, while Java on NT will be based on Win32 threads.

Because these lower—level libraries have so much impact on the actual performance of a Java program, we will devote significant attention to the native libraries. Because POSIX threads are more primitive than Win32 threads, they will be our basis of comparison and explanation. This allows us to explain the inner workings of threads before jumping to the more intricate workings of Java.

A frank note about our motivation is in order here. We have slaved away for countless hours on this book because we're propeller—heads who honestly believe that this technology is a superb thing and that the widespread use of it will make the world a better place for hackers like ourselves.

Your motivations for writing MT programs? You can write your programs better and more easily, they'll run faster, you'll get them to market more quickly, they'll have fewer bugs, and you'll have happier programmers, customers, and higher sales. The only losers in this game are the competitors, who willlag behind you in application speed and quality.

MT is here today. It is now ubiquitous. As a professional programmer, you have an obligation to understand this technology. It may or may not be appropriate for your current project, but you must be able to make that conclusion yourself. This book will give you what you need to make that decision.

Welcome to the world of the future!

Who Should Use This Book

This book aims to give the programmer or technical manager a solid understanding of threads—what they are, how they work, why they are useful, and some of the programming issues surrounding their use. As an introductory text, it does not attempt a deep, detailed analysis of the most current research, but it does come close. After reading this book the reader should have a solid understanding of the fundamentals, be able to write credible, modestly complex, threaded programs, and have the understanding necessary to analyze their own programs and determine the viability of threading them.

This book has been written with the experienced Java programmer in mind. There is a definite UNIX bias, but none of that is essential to understanding. A Java programmer who does not know C will find the POSIX code fragments mildly challenging, although possible to decipher. The concepts should be clear. A technically minded nonprogrammer should be able to follow most of the concepts and understand the value of threads. A nontechnical person will not get much from this book.

This book does not attempt to explain the use of Win32 or POSIX APIs. It does contrast them to Java APIs to explain some of the higher—level Java behavior in lower—level terms.

How This Book Is Organized

Chapter 1, Introduction—In which we discuss the motivation for creating thread libraries, the advent of shared memory multiprocessors, and the interactions between threads and SMP machines.

Chapter 2, Concepts—In which the reader is introduced to the basic concepts of multitasking operating systems and of multithreading as it compares to other programming paradigms. The reader is shown reasons why multithreading is a valuable addition to programming paradigms, and a number of examples of successful deployment are presented.

Chapter 3, Foundations—In which we introduce the reader to the underlying structures upon which threads are built, the construction of the thread itself, and the operating system support that allows efficient implementation.

Chapter 4, Lifecycle—In which the reader is treated to a comprehensive explanation of the intricacies in the life of a thread—birth, life, and death—even death by vile cancellation. A small program that illustrates all these stages concludes the chapter.

Chapter 5, Scheduling—In which we explain the myriad details of various scheduling models and alternative choices that could be made, describe context switching in detail, and delve into gruesome detail on various design options. There is light at the end of the tunnel, however.

Chapter 6, Synchronization—In which the reader is led on a hunt for the intimidating synchronization variable and discovers that it is not actually as frightening as had been thought. Programs illustrating the basic use of the POSIX and Java primitives are shown.

Chapter 7, Complexities—In which a series of more complex synchronization variables and options are presented and the trade—off between them and the simpler ones are discussed. Synchronization problems and techniques for dealing with them conclude the chapter.

Chapter 8, TSD—In which explanations of thread—specific data, their use, and some implementation details are provided.

Chapter 9, Cancellation—In which we describe the acrimonious nature of some programs and how unwanted threads may be disposed of. The highly complex issues surrounding bounded time termination and program correctness are also covered. A simple conclusion is drawn.

Chapter 10, Details—In which a number of minor details are covered.

Chapter 11, Libraries—In which we explore a variety of operating systems issues that bear heavily upon the usability of threads in actual programs. We examine the status of library functions and the programming issues facing them. We look at some design alternatives for library functions.

Chapter 12, Design—In which we explore some designs for programs and library functions. Making both programs and individual functions more concurrent is a major issue in the design of these functions. We look at a variety of code examples and the trade—offs between them.

Chapter 13, RMI—In which we examine RMI and see what it provides in terms of a distributed object programming model. We look at how threading interacts with it and how it uses threads.

Chapter 14, Tools—In which we consider the kinds of new tools that a reader would want when writing a threaded program. An overview of the Solaris tool set is given, as representative of what should be looked for.

Chapter 15, Performance—In which we make things faster, look at general performance issues, political performance issues, and thread specific performance issues. We conclude with a discussion of the actual performance of multithreaded NFS.

Chapter 16, Hardware—In which we look at the various designs for SMP machines (cache architectures, interconnect topologies, atomic instructions, invalidation techniques) and consider how those designs affect our programming decisions. Some optimization possibilities are looked at.

Chapter 17, Examples—In which several complete programs are presented. The details and issues surrounding the way they use threads are discussed, and references to other programs on the Net are made.

Meet the Author

Bil Lewis is a consultant who has taught multithreading to over 3,000 programmers. He held a variety of engineering and marketing positions at Sun Microsystems, and co-authored Multithreaded Programming with Pthreads (Prentice Hall PTR).

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >