 |
 |
 |
 |
 |
 |
Java theory and practice: Are all stateful Web applications broken?
The session state management mechanism provided by the Servlets framework, HttpSession, makes it easy to create stateful applications, but it is also quite easy to misuse. Many Web applications that use HttpSession for mutable data (such as JavaBeans classes) do so with insufficient coordination, exposing themselves to a host of potential concurrency hazards. |
|
Articles |
|
23 Sep 2008 |
|
|
Java theory and practice: Going wild with generics, Part 2
Wildcards can be very confusing when it comes to generics in the Java language, and one of the most common mistakes is to fail to use one of the two forms of bounded wildcards ("super T" and "? extends T") when needed. You've made this mistake? Don't feel bad, even the experts have, and this month Brian Goetz shows you how to avoid it. |
|
Articles |
|
01 Jul 2008 |
|
|
Java theory and practice: Going wild with generics, Part 1
One of the most complicated aspects of generics in the Java language is wildcards, and in particular, the treatment and confusing error messages surrounding wildcard capture. In this installment of Java theory and practice, veteran Java developer Brian Goetz deciphers some of the weirder-looking error messages emitted by javac and offers some tricks and workarounds that can simplify using generics. |
|
Articles |
|
06 May 2008 |
|
|
Java theory and practice: Stick a fork in it, Part 2
One of the additions to the java.util.concurrent packages coming in Java 7 is a library for fork-join-style parallel decomposition. In part one of this series, author Brian Goetz shows how fork-join provides a natural mechanism for decomposing many algorithms to effectively exploit hardware parallelism. In this article, he'll cover the ParallelArray classes, which simplify parallel sorting and searching operations on in-memory data structures. |
|
Articles |
|
04 Mar 2008 |
|
|
Java theory and practice: Stick a fork in it, Part 1
One of the additions to the java.util.concurrent packages coming in Java 7 is a framework for fork-join style parallel decomposition. The fork-join abstraction provides a natural mechanism for decomposing many algorithms to effectively exploit hardware parallelism. The next installment in this series covers the ParallelArray classes, which simplify parallel sorting and searching operations on in-memory data structures. |
|
Articles |
|
13 Nov 2007 |
|
|
Java theory and practice: Managing volatility
The Java language contains two intrinsic synchronization mechanisms: synchronized blocks (and methods) and volatile variables. Both are provided for the purpose of rendering code thread-safe. Volatile variables are the weaker (but sometimes simpler or less expensive) of the two -- but also easier to use incorrectly. In this installment of Java theory and practice, Brian Goetz explores some patterns for using volatile variables correctly and offers some warnings about the limits of its applicability. |
|
Articles |
|
19 Jun 2007 |
|
|
Java theory and practice: The closures debate
Everyone has a favorite feature idea or two for adding to the Java language. With the open-sourcing of the Java platform and the rise in popularity of other languages for server-side applications (JavaScript and Ruby, to name two), the debate over the future of the Java language has never been more vigorous. Should the Java language embrace major new additions, such as closures? Or is that too much messing with a good thing? In this month's Java theory and practice, Brian Goetz reviews the concepts involved and provides details on the two competing closures proposals. |
|
Articles |
|
24 Apr 2007 |
|
|
Java theory and practice: Using Java 5 language features in earlier JDKs
Java 5 added a number of powerful language features: generics, enumerations, annotations, autoboxing, and the enhanced for loop. However, many shops are still tied to JDK 1.4 or earlier and may be for some time to come. But it's still be possible for those developers to take advantage of these powerful language features while continuing to deploy on earlier JVMs. Brian Goetz returns from his hiatus in this installment of Java theory and practice to demonstrate how. |
|
Articles |
|
27 Feb 2007 |
|
|
Java theory and practice: Instrumenting applications with JMX
Debuggers and profilers can provide insight into an application's behavior, but we usually only break out these tools when there's a serious problem. Building monitoring hooks into an application can make it easier to understand what your programs are doing without breaking out the debugger. Now that Java Management Extensions (JMX) is built into the Java SE platform, and the jconsole viewer provides a universal monitoring GUI, using JMX to provide a window into your application is easier and more effective than ever. |
|
Articles |
|
19 Sep 2006 |
|
|
Java theory and practice: Testing with leverage, Part 3
The first two installments in this series showed how static analysis tools like FindBugs can provide greater leverage in managing software quality by focusing on entire categories of bugs rather than on specific bug instances. In this final installment on testing, Brian Goetz examines another technique for smoking out bugs that violate design rules: aspects. |
|
Articles |
|
22 Aug 2006 |
|
|
Java theory and practice: Testing with leverage, Part 2
June's Java theory and practice column demonstrated how static analysis tools like FindBugs can bring greater leverage to bear on managing software quality by focusing on entire categories of bugs rather than on specific bug instances. In this month's installment, resident exterminator Brian Goetz details the process of constructing and tuning a nontrivial bug pattern detector. |
|
Articles |
|
25 Jul 2006 |
|
|
Java theory and practice: Testing with leverage, Part 1
Back in June 2004, veteran exterminator Brian Goetz introduced the FindBugs static code analysis tool, which can detect bugs even in well-tested software. This month, he revisits that topic and looks at how static analysis tools can change the way you manage software quality by aiming development resources at entire classes of bugs rather than specific instances. |
|
Articles |
|
20 Jun 2006 |
|
|
Java theory and practice: Dealing with InterruptedException
Many Java language methods, such as Thread.sleep() and Object.wait(), throw InterruptedException. You can't ignore it because it's a checked exception, but what should you do with it? In this month's Java theory and practice, concurrency expert Brian Goetz explains what InterruptedException means, why it is thrown, and what you should do when you catch one. |
|
Articles |
|
23 May 2006 |
|
|
Java theory and practice: Introduction to nonblocking algorithms
Java 5.0 makes it possible for the first time to develop nonblocking algorithms in the Java language, and the java.util.concurrent package uses this capability extensively. Nonblocking algorithms are concurrent algorithms that derive their thread safety not from locks, but from low-level atomic hardware primitives such as compare-and-swap. Nonblocking algorithms can be extremely difficult to design and implement, but they can offer better throughput and greater resistance to liveness problems such as deadlock and priority inversion. In this installment of Java theory and practice, concurrency guru Brian Goetz illustrates how several of the simpler nonblocking algorithms work. |
|
Articles |
|
18 Apr 2006 |
|
|
Java theory and practice: Good housekeeping practices
Garbage collection is nearly everyone's favorite feature of the Java platform; it simplifies development and eliminates entire categories of potential code errors. But while garbage collection generally allows you to ignore resource management, sometimes you have to do some housekeeping on your own. In this month's Java theory and practice, Brian Goetz discusses the limitations of garbage collection and identifies situations when you have to do your own housecleaning. |
|
Articles |
|
21 Mar 2006 |
|
|
Java theory and practice: The pseudo-typedef antipattern
The addition of generics to the Java language complicated the type system and increased the verbosity of many variable and method declarations. Because no "typedef" facility was provided for defining short names for types, some developers have turned to extension as a "poor man's typedef," with less than good results. In this month's Java theory and practice, Java expert Brian Goetz explains the limitations of this "antipattern." |
|
Articles |
|
21 Feb 2006 |
|
|
Java theory and practice: Plugging memory leaks with soft references
In the previous installment of Java theory and practice, Java sanitation engineer Brian Goetz examined weak references, which let you put the garbage collector on notice that you want to maintain a reference to an object without preventing it from being garbage collected. This month, he explains another form of Reference object, soft references, which can also enlist the aid of the garbage collector in managing memory usage and eliminating potential memory leaks. |
|
Articles |
|
24 Jan 2006 |
|
|
Java theory and practice: Plugging memory leaks with weak references
While programs in the Java language are theoretically immune from "memory leaks," there are situations in which objects are not garbage collected even though they are no longer part of the program's logical state. This month, sanitation engineer Brian Goetz explores a common cause of unintentional object retention and shows how to plug the leak with weak references. |
|
Articles |
|
22 Nov 2005 |
|
|
Java theory and practice: Synchronization optimizations in Mustang
In the September installment of Java theory and practice, columnist Brian Goetz examined escape analysis, an optimization that has been on the "to-do" list for many JVMs for quite some time and which is expected in HotSpot in the Mustang (Java SE 6) release. Escape analysis can be used to convert heap-based object allocation into the less-expensive, stack-based allocations, but it can also be used to make other optimization decisions as well, including optimizing the use of synchronization. This month Brian introduces some of the synchronization optimizations slated for Mustang. Note: This column describes features of a future version of Sun's HotSpot JVM implementation. Specific features discussed herein may or may not appear in Java SE 6 ("Mustang"); some may be delayed until Java SE 7 ("Dolphin"). |
|
Articles |
|
18 Oct 2005 |
|
|
Java theory and practice: Urban performance legends, revisited
The Java language is the target of a lot of abuse for performance. And while some of it may well be deserved, a tour of message board and newsgroup postings on the subject shows that there is a great deal of misunderstanding about how a Java Virtual Machine (JVM) actually works. In this month's Java theory and practice, Brian Goetz pokes some holes in the oft-repeated performance myth of slow allocation in JVMs. |
|
Articles |
|
27 Sep 2005 |
|
|
Java theory and practice: Decorating with dynamic proxies
The dynamic proxy facility, part of the java.lang.reflect package and added to the JDK in version 1.3, allows programs to create proxy objects, which can implement one or more known interfaces and dispatch calls to interface methods programmatically using reflection instead of using the built-in virtual method dispatch. This process allows implementations to "intercept" method calls and reroute them or add functionality dynamically. This month, Brian Goetz explores several applications for dynamic proxies. |
|
Articles |
|
30 Aug 2005 |
|
|
Java theory and practice: Be a good (event) listener
The Observer pattern, most often seen in Swing development, is also very useful for decoupling components in situations other than GUI applications. However, some common pitfalls with registering or invoking listeners exist. In this installment of Java theory and practice, Java therapist Brian Goetz offers some feel-good advice on how to be a good listener -- and how to be nice to your listeners, too. |
|
Articles |
|
26 Jul 2005 |
|
|
Java theory and practice: Make database queries without the database
When you have a hammer, everything looks like a nail (as the old saying goes). But what if you don't have a hammer? Well, sometimes, you can borrow a hammer. Then, hammer in hand, you can bang the virtual nails with the borrowed hammer, return it, and no one is the wiser. In this month's Java theory and practice, Brian Goetz demonstrates how data manipulation hammers such as SQL or XQuery can be applied to ad-hoc data. |
|
Articles |
|
31 May 2005 |
|
|
Java theory and practice: Enable initialization atomicity
Decisions made during API design can have an effect on the API's usability. In designing an API, you need to put yourself in your user's shoes, imagining how the API might be used, and try and make the common use cases convenient for the user. This month, columnist Brian Goetz discusses an API design technique, the self-return idiom, that can make life easier for users of your API in certain circumstances. Share your thoughts on this article with the author and other readers in the accompanying discussion forum. |
|
Articles |
|
27 Apr 2005 |
|
|
Java theory and practice: Screen-scraping with XQuery
XQuery is a W3C standard for extracting information from XML documents, currently spanning 14 working drafts. While the majority of interest in XQuery is centered around querying large bases of semi-structured document data, XQuery can be surprisingly effective for some much more mundane uses as well. In this month's Java theory and practice, columnist Brian Goetz shows you how XQuery can be used effectively as an HTML screen-scraping engine. |
|
Articles |
|
22 Mar 2005 |
|
|
Java theory and practice: Anatomy of a flawed microbenchmark
Software engineers are notoriously obsessed, sometimes excessively, with performance. While sometimes performance is the most important requirement in a software project, as it might be when developing protocol routing software for a high-speed switch, most of the time performance needs to be balanced against other requirements, such as functionality, reliability, maintainability, extensibility, time to market, and other business and engineering considerations. In this month's Java theory and practice, columnist Brian Goetz explores why it is so much harder to measure the performance of Java language constructs than it looks. |
|
Articles |
|
22 Feb 2005 |
|
|
Java theory and practice: Generics gotchas
Generic types, added in JDK 5.0, are a significant enhancement to type safety in the Java language. However, some aspects of generics may seem confusing, or even downright bizarre, to first-time users. In this month's Java theory and practice, Brian Goetz examines the common pitfalls that ensnare first-time users of generics. |
|
Articles |
|
25 Jan 2005 |
|
|
Java theory and practice: Dynamic compilation and performance measurement
Writing and interpreting performance benchmarks for dynamically compiled languages, such as Java, is far more difficult than for statically compiled languages like C or C++. In this installment of Java theory and practice, Brian Goetz explores a few of the many ways in which dynamic compilation can complicate performance testing. |
|
Articles |
|
21 Dec 2004 |
|
|
Java theory and practice: Going atomic
Until JDK 5.0, it was not possible to write wait-free, lock-free algorithms in the Java language without using native code. The addition of the atomic variable classes in java.util.concurrent changes that situation. Follow along with concurrency expert Brian Goetz as he explains how these new classes have enabled the development of highly scalable nonblocking algorithms in the Java language. Share your thoughts on this article with the author and other readers in the accompanying discussion forum. |
|
Articles |
|
23 Nov 2004 |
|
|
Java theory and practice: More flexible, scalable locking in JDK 5.0
JDK 5.0 offers developers some powerful new choices for developing high-performance concurrent applications. For example, the ReentrantLock class in java.util.concurrent.lock is offered as a replacement for the synchronized facility of the Java language -- it has the same memory semantics, the same locking semantics, better performance under contention, and features not offered by synchronized. Does this mean that we should forget about synchronized, and instead use ReentrantLock exclusively? Concurrency expert Brian Goetz returns from his summer hiatus to supply the answer. |
|
Articles |
|
26 Oct 2004 |
|
|
Java theory and practice: State replication in the Web tier
How state will be managed and replicated in a clustered server application has a significant impact on the scalability of the application. Many Java applications store state in the HttpSession provided by the Servlet API. This article examines some of the options for HttpSession replication and how to most effectively use HttpSession to provide good scalability and performance. |
|
Articles |
|
29 Jul 2004 |
|
|
Java theory and practice: Kill bugs dead
The FindBugs tool is a powerful tool for auditing your code for compliance with good design practices and represents a huge step forward in the state-of-the-art of real-world code analysis tools. |
|
Articles |
|
29 Jun 2004 |
|
|
Java theory and practice: The exceptions debate
When should you use checked versus unchecked exceptions in Java classes? The prevailing wisdom is to use checked exceptions in nearly all cases, but some Java luminaries have begun to think otherwise. This month, columnist Brian Goetz examines the exceptions debate and offers guidance on when and how to use unchecked exceptions. |
|
Articles |
|
25 May 2004 |
|
|
Java theory and practice: Coaxing J2EE out of the container
Most projects fall squarely into either the category of J2EE application or J2SE application. However, there are a number of J2EE technologies that can exist outside of the J2EE container, and some J2SE applications may benefit from them. This month, Brian Goetz looks at how some J2EE services can be used in J2SE applications. Share your thoughts on this article with the author and other readers in the accompanying discussion forum. |
|
Articles |
|
20 Apr 2004 |
|
|
Java theory and practice: Fixing the Java Memory Model, Part 2
JSR 133, which has been active for nearly three years, has recently issued its public recommendation on what to do about the Java Memory Model (JMM). In Part 1 of this series, columnist Brian Goetz focused on some of the serious flaws that were found in the original JMM, which resulted in some surprisingly difficult semantics for concepts that were supposed to be simple. This month, he reveals how the semantics of volatile and final will change under the new JMM, changes that will bring their semantics in line with most developers' intuition. Some of these changes are already present in JDK 1.4; others will have to wait until JDK 1.5. Share your thoughts on this article with the author and other readers in the accompanying discussion forum. |
|
Articles |
|
30 Mar 2004 |
|
|
Java theory and practice: Fixing the Java Memory Model, Part 1
JSR 133, which has been active for nearly three years, has recently issued its public recommendation on what to do about the Java Memory Model (JMM). Several serious flaws were found in the original JMM, resulting in some surprisingly difficult semantics for concepts that were supposed to be simple, like volatile, final, and synchronized. In this installment of Java theory and practice, Brian Goetz shows how the semantics of volatile and final will be strengthened in order to fix the JMM. Some of these changes have already been integrated in JDK 1.4; others are slated for inclusion in JDK 1.5. |
|
Articles |
|
24 Feb 2004 |
|
|
Java theory and practice: Garbage collection and performance
The past two installments of Java theory and practice have discussed various techniques for garbage collection and the basics of the JDK 1.4.1 garbage collectors. This month, columnist Brian Goetz looks at the performance impact of the choice of collector, how various coding idioms interact with the garbage collector, and how allocation and other related costs have changed in Java virtual machines over the past several years. |
|
Articles |
|
27 Jan 2004 |
|
|
Java theory and practice: Garbage collection in the HotSpot JVM
Brian Goetz examines how the 1.4.1 JVM actually handles garbage collection, including some of the new garbage collection options for multiprocessor systems. |
|
Articles |
|
25 Nov 2003 |
|
|
Java theory and practice: A brief history of garbage collection
Garbage collection has been an integral part of many programming languages and has been in use since the early 1960s. In this article, Brian Goetz describes the most common techniques for garbage collection. |
|
Articles |
|
28 Oct 2003 |
|
|
Java theory and practice: Characterizing thread safety
In July our concurrency expert Brian Goetz described the Hashtable and Vector classes as being conditionally thread-safe. Shouldn't a class either be thread-safe or not? Unfortunately, thread safety is not an all-or-nothing proposition, and it is surprisingly difficult to define. But, as Brian explains in this month's Java theory and practice, it is critically important that you make an effort to classify the thread safety of your classes in their Javadoc. |
|
Articles |
|
23 Sep 2003 |
|
|
Java theory and practice: Building a better HashMap
Brian Goetz dives into the code of ConcurrentHashMap and looks at how it achieves excellent throughput and concurrency without compromising thread safety. |
|
Articles |
|
21 Aug 2003 |
|
|
Java theory and practice: Concurrent collections classes
In addition to many other useful concurrency building blocks, Doug Lea's util.concurrent package contains high-performance, thread-safe implementations for workhorse collection types List and Map. This month, Brian Goetz shows you how many concurrent programs will benefit from simply replacing Hashtable or synchronizedMap with ConcurrentHashMap. |
|
Articles |
|
23 Jul 2003 |
|
|
Java theory and practice: Whose object is it, anyway?
While garbage collection means that Java developers don't have to worry (much) about memory leaks, sometimes we still do have to worry about object ownership to prevent data races and unwanted side effects. In this article, Brian Goetz identifies some of the situations where Java developers must pay attention to object ownership. |
|
Articles |
|
24 Jun 2003 |
|
|
Java theory and practice: Hashing it out
In this installment of Java theory and practice, Java developer Brian Goetz shows you the rules and guidelines you should follow when creating Java classes in order to define hashCode() and equals() effectively and appropriately. |
|
Articles |
|
27 May 2003 |
|
|
Java theory and practice: Urban performance legends
Many pointers and tips about Java performance tuning are a lot like urban legends -- someone, somewhere, passes on a tip that has (or had) some basis in fact, but through its continued retelling, has lost what truth it once contained. Brian Goetz examines some of these urban performance legends and sets the record straight. |
|
Articles |
|
22 Apr 2003 |
|
|
Java theory and practice: Performance management -- do you have a plan?
Brian Goetz discusses some of the most common performance mistakes he's seen in projects using the Java language. While there are many types of programming choices that can lead to performance problems, often mistakes of management and approach are the culprit. |
|
Articles |
|
25 Mar 2003 |
|
|
Java theory and practice: To mutate or not to mutate?
In this article, Brian Goetz explains some of the benefits of immutability and some guidelines for constructing immutable classes. While immutability may not necessarily make sense for all classes, most programs have at least a few classes that would benefit from being immutable. |
|
Articles |
|
18 Feb 2003 |
|
|
Java theory and practice: Where's your point?
Many programmers go their entire career without using fixed point or floating point numbers, with the possible exception of the odd timing test or benchmark. The Java language and class libraries support two sorts of non-integral numeric types -- IEEE 754 floating point and arbitrary-precision decimal. In this article, Brian Goetz looks at some of the traps and gotchas often encountered when using non-integral numeric types in Java programs. |
|
Articles |
|
01 Jan 2003 |
|
|
Java theory and practice: Concurrency made simple (sort of)
Like many other application infrastructure services, concurrency utility classes such as work queues and thread pools are often needlessly rewritten from scratch for every project. This month, Brian Goetz offers an introduction to Doug Lea's util.concurrent package, a high-quality, widely used, open source package of concurrency utilities. |
|
Articles |
|
01 Nov 2002 |
|
|
Java theory and practice: Is that your final answer?
The final keyword is often misused -- it is overused when declaring classes and methods, and underused when declaring instance fields. This month, Java practitioner Brian Goetz explores some guidelines for the effective use of final. |
|
Articles |
|
01 Oct 2002 |
|
|
Java theory and practice: Hey, where'd my thread go?
If you're not careful, threads can disappear from server applications without a (stack) trace. In this article, threading expert Brian Goetz offers some techniques for both prevention and detection of threads going AWOL. |
|
Articles |
|
01 Sep 2002 |
|
|
Java theory and practice: I have to document THAT?
The Java language takes an integrated approach to API documentation through the Javadoc comment convention. The Javadoc tool can help generate pretty API documentation, but the vast majority of Java API documentation out there is simply awful. Because it is part of the source code, the responsibility for the documentation of APIs falls squarely on the engineer. In this article, Brian rants about the current state of Java documentation practices and offers some guidelines on how to write more useful Javadoc. |
|
Articles |
|
01 Aug 2002 |
|
|
Java theory and practice: Thread pools and work queues
One of the most common questions posted on our Multithreaded Java programming discussion forum is some version of how to create a thread pool. In nearly every server application, the question of thread pools and work queues comes up. In this article, Brian Goetz explores the motivations for thread pools, some basic implementation and tuning techniques, and some common hazards to avoid. |
|
Articles |
|
01 Jul 2002 |
|
|
Java theory and practice: Safe construction techniques
Concurrent programming in Java applications is more complicated than it looks: there are several subtle (and not so subtle) ways to create data races and other concurrency hazards in Java programs. In this installment of Java theory and practice, Brian Goetz looks at a common threading hazard: allowing the this reference to escape during construction. This harmless-looking practice can cause unpredictable and undesirable results in your Java programs. |
|
Articles |
|
01 Jun 2002 |
|
|
Java theory and practice: Understanding JTS -- Balancing safety and performance
In this final installment of his series on JTS, Brian Goetz looks at the facilities that J2EE offers for managing transaction demarcation and isolation and some guidelines for using them effectively. |
|
Articles |
|
01 May 2002 |
|
|
Java theory and practice: Understanding JTS -- The magic behind the scenes
In Part 1 of this series on transactions, we covered the basics of what transactions are and why they are critical to building reliable distributed applications. In this installment, we'll explore how J2EE applications are structured into transactions, and how JTS and the J2EE container manage to make transaction services, including transaction demarcation, resource enlistment, and transaction propagation, nearly invisible to the component programmer. |
|
Articles |
|
01 Apr 2002 |
|
|
Java theory and practice: Understanding JTS -- An introduction to transactions
The Java Transaction Service is a key element of the J2EE architecture. Together with the Java Transaction API, it enables us to build distributed applications that are robust to all sorts of system and network failures. This first installment of a three-part series covers the basics of what transactions are and why they are critical to building reliable distributed applications. |
|
Articles |
|
01 Mar 2002 |
|
|
Java theory and practice: Should you use JMS in your next enterprise application?
Welcome to Java theory and practice, a new monthly column by veteran Java developer Brian Goetz. This column aims to explore that elusive juncture where design principles meet the requirements to solve real-world problems. Each month, we'll explore design patterns, principles of reliable software design, and why best practices are best, with an eye to how they are applied to real problems. This month, Brian takes a look at enterprise message queuing technology. |