Threads are a fundamental part of the Java platform. As multicore processors become the norm, using concurrency effectively becomes essential for building high-performance applications. Java SE 5 and 6 are a huge step forward for the development of concurrent applications, with improvements to the Java Virtual Machine to support high-performance, highly scalable concurrent classes and a rich set of new concurrency building blocks. In Java Concurrency in Practice , the creators of these new facilities explain not only how they work and how to use them, but also the motivation and design patterns behind them. However, developing, testing, and debugging multithreaded programs can still be very difficult; it is all too easy to create concurrent programs that appear to work, but fail when it matters most: in production, under heavy load. Java Concurrency in Practice arms readers with both the theoretical underpinnings and concrete techniques for building reliable, scalable, maintainable concurrent applications. Rather than simply offering an inventory of concurrency APIs and mechanisms, it provides design rules, patterns, and mental models that make it easier to build concurrent programs that are both correct and performant. This book covers: Basic concepts of concurrency and thread safety Techniques for building and composing thread-safe classes Using the concurrency building blocks in java.util.concurrent Performance optimization dos and don'ts Testing concurrent programs Advanced topics such as atomic variables, nonblocking algorithms, and the Java Memory Model
"Java 7 Concurrency Cookbook" is a practical Cookbook packed with real-world solutions. Intermediate-advanced level Java developers will learn from task-based recipes to use Java's concurrent API to program thread safe solutions.If you are a Java developer who wants to take your knowledge of concurrent programming and multithreading further, as well as discover the new concurrency features of Java 7, then "Java 7 Concurrency Cookbook" is for you.
Master the principles to make applications robust, scalable and responsive About This Book Implement concurrent applications using the Java 9 Concurrency API and its new components Improve the performance of your applications and process more data at the same time, taking advantage of all of your resources Construct real-world examples related to machine learning, data mining, natural language processing, and more Who This Book Is For This book is for competent Java developers who have basic understanding of concurrency, but knowledge of effective implementation of concurrent programs or usage of streams for making processes more efficient is not required What You Will Learn Master the principles that every concurrent application must follow See how to parallelize a sequential algorithm to obtain better performance without data inconsistencies and deadlocks Get the most from the Java Concurrency API components Separate the thread management from the rest of the application with the Executor component Execute phased-based tasks in an efficient way with the Phaser components Solve problems using a parallelized version of the divide and conquer paradigm with the Fork / Join framework Find out how to use parallel Streams and Reactive Streams Implement the “map and reduce” and “map and collect” programming models Control the concurrent data structures and synchronization mechanisms provided by the Java Concurrency API Implement efficient solutions for some actual problems such as data mining, machine learning, and more In Detail Concurrency programming allows several large tasks to be divided into smaller sub-tasks, which are further processed as individual tasks that run in parallel. Java 9 includes a comprehensive API with lots of ready-to-use components for easily implementing powerful concurrency applications, but with high flexibility so you can adapt these components to your needs. The book starts with a full description of the design principles of concurrent applications and explains how to parallelize a sequential algorithm. You will then be introduced to Threads and Runnables, which are an integral part of Java 9's concurrency API. You will see how to use all the components of the Java concurrency API, from the basics to the most advanced techniques, and will implement them in powerful real-world concurrency applications. The book ends with a detailed description of the tools and techniques you can use to test a concurrent Java application, along with a brief insight into other concurrency mechanisms in JVM. Style and approach This is a complete guide that implements real-world examples of algorithms related to machine learning, data mining, and natural language processing in client/server environments. All the examples are explained using a step-by-step approach.
Are you looking for a deeper understanding of the Java™ programming language so that you can write code that is clearer, more correct, more robust, and more reusable? Look no further! Effective Java™, Second Edition, brings together seventy-eight indispensable programmer’s rules of thumb: working, best-practice solutions for the programming challenges you encounter every day. This highly anticipated new edition of the classic, Jolt Award-winning work has been thoroughly updated to cover Java SE 5 and Java SE 6 features introduced since the first edition. Bloch explores new design patterns and language idioms, showing you how to make the most of features ranging from generics to enums, annotations to autoboxing. Each chapter in the book consists of several “items” presented in the form of a short, standalone essay that provides specific advice, insight into Java platform subtleties, and outstanding code examples. The comprehensive descriptions and explanations for each item illuminate what to do, what not to do, and why. Highlights include: New coverage of generics, enums, annotations, autoboxing, the for-each loop, varargs, concurrency utilities, and much more Updated techniques and best practices on classic topics, including objects, classes, libraries, methods, and serialization How to avoid the traps and pitfalls of commonly misunderstood subtleties of the language Focus on the language and its most fundamental libraries: java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io Simply put, Effective Java™, Second Edition, presents the most practical, authoritative guidelines available for writing efficient, well-designed programs.
Master the art of fast, effective Java development with the power of concurrent and parallel programming About This Book Get detailed coverage of important recipes on multi-threading and parallel programming This book takes a close look at the Java 9 APIs and their impact on concurrency See practical examples on thread safety, high-performance classes, safe sharing, and a whole lot more Who This Book Is For The book is for Java developers and programmers at an intermediate to advanced level. It will be especially useful for developers who want to take advantage of task-based recipes using Java 9's concurrent API to program thread-safe solutions. What You Will Learn Find out to manage the basic components of the Java Concurrency API Use synchronization mechanisms to avoid data race conditions and other problems of concurrent applications Separate the thread management from the rest of the application with the Executor framework Solve problems using a parallelized version of the divide and conquer paradigm with the Fork / Join framework Process massive data sets in an optimized way using streams and reactive streams See which data structures we can use in concurrent applications and how to use them Practice efficient techniques to test concurrent applications Get to know tips and tricks to design concurrent applications In Detail Writing concurrent and parallel programming applications is an integral skill for any Java programmer. Java 9 comes with a host of fantastic features, including significant performance improvements and new APIs. This book will take you through all the new APIs, showing you how to build parallel and multi-threaded applications. The book covers all the elements of the Java Concurrency API, with essential recipes that will help you take advantage of the exciting new capabilities. You will learn how to use parallel and reactive streams to process massive data sets. Next, you will move on to create streams and use all their intermediate and terminal operations to process big collections of data in a parallel and functional way. Further, you'll discover a whole range of recipes for almost everything, such as thread management, synchronization, executors, parallel and reactive streams, and many more. At the end of the book, you will learn how to obtain information about the status of some of the most useful components of the Java Concurrency API and how to test concurrent applications using different tools. Style and approach This recipe-based book will allow you to explore the exciting capabilities of concurrency in Java. After reading this book, you will be able to comfortably build parallel applications in Java 9.
This concise book empowers all Java developers to master the complexity of the Java thread APIs and concurrency utilities. This knowledge aids the Java developer in writing correct and complex performing multithreaded applications. Java's thread APIs and concurrency utilities are among its most powerful and challenging APIs and language features. Java beginners typically find it very difficult to use these features to write correct multithreaded applications. Threads and the Concurrency Utilities helps all Java developers master and use these capabilities effectively. This book is divided into two parts of four chapters each. Part 1 focuses on the Thread APIs and Part 2 focuses on the concurrency utilities. In Part 1, you learn about Thread API basics and runnables, synchronization and volatility, waiting and notification, and the additional capabilities of thread groups, thread local variables, and the Timer Framework. In Part 2, you learn about concurrency utilities basics and executors, synchronizers, the Locking Framework, and the additional capabilities of concurrent collections, atomic variables, and the Fork/Join Framework. Each chapter ends with select exercises designed to challenge your grasp of the chapter's content. An appendix provides the answers to these exercises. A second appendix explores how threads are used by various standard class library APIs. Specifically, you learn about threads in the contexts of Swing, JavaFX, and Java 8's Streams API. What You Will Learn • How to do thread runnables, synchronization, volatility, waiting and notification, thread groups, thread local variables, and the Timer Framework• How to create multithreaded applications that work correctly.• What are concurrency utilities basics and executors• What are synchronizers, the Locking Framework, concurrent collections, atomic variables, and the Fork/Join Framework and how to use them• How to leverage the concurrency utilities to write more complex multithreaded applications and achieve greater performance• How to apply thread usage in Swing, JavaFX, and Java 8 Streams API contexts Audience The primary audience is Java beginners and the secondary audience is more advanced Java developers who have worked with the Thread APIs and the Concurrency Utilities.
Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show users all these concurrency styles so they can compare and choose what works best for their applications.
"Every programming language has its quirks. This lively book reveals oddities of the Java programming language through entertaining and thought-provoking programming puzzles." --Guy Steele, Sun Fellow and coauthor of The Java™ Language Specification "I laughed, I cried, I threw up (my hands in admiration)." --Tim Peierls, president, Prior Artisans LLC, and member of the JSR 166 Expert Group How well do you really know Java? Are you a code sleuth? Have you ever spent days chasing a bug caused by a trap or pitfall in Java or its libraries? Do you like brainteasers? Then this is the book for you! In the tradition of Effective Java™, Bloch and Gafter dive deep into the subtleties of the Java programming language and its core libraries. Illustrated with visually stunning optical illusions, Java™ Puzzlers features 95 diabolical puzzles that educate and entertain. Anyone with a working knowledge of Java will understand the puzzles, but even the most seasoned veteran will find them challenging. Most of the puzzles take the form of a short program whose behavior isn't what it seems. Can you figure out what it does? Puzzles are grouped loosely according to the features they use, and detailed solutions follow each puzzle. The solutions go well beyond a simple explanation of the program's behavior--they show you how to avoid the underlying traps and pitfalls for good. A handy catalog of traps and pitfalls at the back of the book provides a concise taxonomy for future reference. Solve these puzzles and you'll never again fall prey to the counterintuitive or obscure behaviors that can fool even the most experienced programmers.
Bruce Tate, author of the Jolt Award-winning Better, Faster, Lighter Java has an intriguing notion about the future of Java, and it's causing some agitation among Java developers. Bruce believes Java is abandoning its base, and conditions are ripe for an alternative to emerge. In Beyond Java, Bruce chronicles the rise of the most successful language of all time, and then lays out, in painstaking detail, the compromises the founders had to make to establish success. Then, he describes the characteristics of likely successors to Java. He builds to a rapid and heady climax, presenting alternative languages and frameworks with productivity and innovation unmatched in Java. He closes with an evaluation of the most popular and important programming languages, and their future role in a world beyond Java. If you are agree with the book's premise--that Java's reign is coming to an end--then this book will help you start to build your skills accordingly. You can download some of the frameworks discussed and learn a few new languages. This book will teach you what a new language needs to succeed, so when things do change, you'll be more prepared. And even if you think Java is here to stay, you can use the best techniques from frameworks introduced in this book to improve what you're doing in Java today.