Copyright 2012 press.adam-bien.com.All rights reserved.
Cover Picture: The front-cover photo was taken duringone of the airhacks.comworkshops. It is an Airstream trailer/airplane hybrid transformed into a snackbar. The tower shown on the back cover is located about 300 meters away fromthe workshop venue at Munich's airport.
Preface
Since the publication of the first edition of RealWorld Java EE PatternsRethinking Best Practices , the enterprise landscape hasdramatically changed. Because of theamazing productivity provided by Java EE, smaller companies and startups havebegun to use Java EE for building a variety of interesting applications, fromNoSQL data store integration to communication with robots over sockets.
I used the patterns and utilities describedin the first edition Rethinking in all my Java EE projects. Gettingthings done became more important than any shiny frameworks. With a littlehelp from Java EE 6, previously challenging tasks turned into a few lines ofcode and couple of annotations. I began to gather and re-implement thesolutions from my projects and push them frequently to http://kenai.com/projects/javaee-patterns.
The Rethinking book is a catalog of ideas, patterns,and workarounds. Many readers asked for a real world application built upon theconcepts described in the Rethinking book. It was a challenging request, because,as a consultant, I always have to sign an NDA before any of my real workstarts. However, during one of my nightly hacking sessions, I got a spontaneousidea for my second book, Real World Java EE Night HacksDissecting theBusiness Tier (press.adam-bien.com). In theNight Hacks book, I described one of my Java EE 6 hacksa blogstatistics application called x-ray (x-ray.adam-bien.com),which I created for real time monitoring of my blog: blog.adam-bien.com. I developed x-ray fromscratch; it is a real world application that is dangerous (it could crash myblog, which has approximately 10,000 visitors a day) and there is no NDA, so itwas perfectly suitable as a sample application for a book.
The x-ray application is a native Java EE 6application entirely built with concepts from the first edition of the Rethinkingbook; I even had some specific problems to solve, the solution to which emergedas new patterns. The Late Starter, Configurator, and Telemetry Providerpatterns were extracted almost without any modification from x-ray.
Also, my continuous emphasis on theimportance of stress testing resulted in a new project: lightfish.adam-bien.com. I built theLightFish monitoring application with Java EE 6 and used scripting forescalation of suspicious behavior. I extracted some code from LightFish toprovide you with another NDA-free samplethe Fluid Logic pattern.
The first edition of Rethinking camewith a Java EE Connector Architecture (JCA) 1.5 connector implementation, whichgot some attention as well. In this second edition of Rethinking, Iimplemented a JCA 1.6 connector from scratch and extracted it into a standaloneApache-licensed project: connectorz.adam-bien.com.
I'm always open to feedback and discussion-so I can learn fromyou, the reader. Just drop me an email (abien@adam-bien.com) and I'll be sureto incorporate your feedback in a future update of the book. Also, keep an eyeon my blog (blog.adam-bien.com), where I willcontinue to cover the topics discussed in this book.
If youd like to code something with me inreal time, check out workshops.adam-bien.com.I regularly organize short hacking workshops at Munichs airport. I call thatairhacks.com.
Special thanks to my wife Kinga (design.graphikerin.com) for the cover,Patrick for the in-depth technical review and unconventional feedback, and myeditor Karen Perkins (http://www.linkedin.com/in/karenjperkins)for editing and pragmatic collaboration.
Shortly before my summer vacation at JavaOne2012,
Adam Bien, adam-bien.com
The book Real World Java EE Night Hacks--Dissecting the Business Tier describes end-to-end development of a real world Java EE application.After the first edition of the Real World Java EE Patterns--Rethinking Best Practices I gotmany requests for a book about developing a Java EE application from scratch. Real World Java EE Night Hacks walks you through the Java EE 6 best practices and patterns used to create a real world application called x-ray .X-ray is a high-performance blog statistics application built with nothing but vanilla Java EE 6 leveraging the synergies between the JAX-RS, EJB 3.1, JPA 2, and CDI 1.0 APIs
James Gosling "father of Java" also liked Night Hacks --and wrote a preface.
There is also an executable and interactive version of both books available. See you at: airhacks.com!
A Brief History of Java EE
If youre new to Java Platform, EnterpriseEdition (Java EE), you might be wondering about the platforms complexity andAPIs. The Java EE platform is not the product of a single company; it is anabstraction of many established products, libraries, and frameworks.Distributed computing, not Java EE, is what makes our daily work sochallenging. For a better understanding of Java EE, I will start with itshistory and explain the basics of synchronization and transactions-the basics of ourdistributed world.
If you are a Java EE expert and already knowthe advantages of transaction management, isolation levels, and concurrencycontrol, you can safely skip this chapter.
The Rise and Fall of Applets
The beginnings of Java EE can be traced backto the introduction of Java applets in the first Java release in 1995. WhenNetscape introduced support for applets in its Netscape Navigator browser inthe mid-1990s, Java quickly gained in popularity. Everything was turned intoapplets; even simple static pages became animated. Although applets quicklygained in size and became more sophisticated, most of their functionality washandled on the back end, making client/server communication essential for evensimple operations.
The introduction of Remote Method Invocation(RMI) in the Java Development Kit (JDK) 1.1 addressed the need for atransparent client/server communication, but it didnt solve the problementirely. The first, Comet-like (http://en.wikipedia.org/wiki/Comet_(programming))style of communication was implemented so the server could push data to thebrowser. First attempts for real-time applet/server communication were madewith long polling, although there was also a lot buzz around raw-socketclient/server communication. In fact, raw TCP-based communication style isgetting some buzz right nowwith the advent of WebSockets (http://en.wikipedia.org/wiki/WebSocket).
Java Database Connectivity (JDBC), alsointroduced in JDK 1.1, facilitated the implementation of low-level access torelational databases and even helped control local transactions. Severalapplets shared a single, remote server instance, which accessed the databaseusing JDBC. And thats when things became problematic. RMI code isntthread-safe. Only one instance of the UnicastRemoteObject was bound to aparticular port, which was shared among different users or threads. Thisinstance was actually a distributed singleton and maintained the connections tothe database as well. Database transactions could be managed only by using theparticular java.sql.Connection instance; the JavaTransaction API (JTA) had yet to be written. Access to the shared connectionhad to be serialized to ensure consistency, but demand for scalabilityincreased significantly at the same time.