Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API
Java EE (Java Platform, Enterprise Edition) applications, regardless of the application server they are deployed to, tend to experience the same sets of problems. As a Java EE tuner, I have been exposed to a variety of environments and have made some observations about common problems. In this capacity, I see my role as similar to that of an automobile mechanic: you tell your mechanic that the engine is chirping; then he asks you a series of questions that guide you in quantifying the nature, location, and circumstances of the chirp. From this information, he forms a good idea about a handful of possible causes of the problem.
In much the same way, I spend the first day of a tuning engagement interviewing my clients. During this interview, I look for known problems as well as architectural decisions that may negatively affect the performance of the application. With an understanding of the application architecture and the symptoms of the problem, I greatly increase my chances of resolving the problem. In this chapter, I share some of the common problems that I have encountered in the field and their symptoms. Hopefully, this article can serve as a troubleshooting manual for your Java EE environment.
One of the most common problems that plagues enterprise applications is the dreaded OutOfMemoryError. The error is typically followed by one of the following:
Regardless of the symptoms, you will most likely need to reboot the application server before performance returns to normal.
Before you attempt to resolve an out-of-memory error, first understanding how it can occur is beneficial. If the JVM runs
out of memory anywhere in its process memory space, including all regions in the heap as well as the permanent memory space,
and a process attempts to create a new object instance, the garbage collector executes to try to free enough memory to allow
the new object's creation. If the garbage collector cannot free enough memory to hold the new object, then it throws an OutOfMemoryError.
Out-of-memory errors most commonly result from Java memory leaks. Recall from previous discussions that a Java memory leak
is the result of maintaining a lingering reference to an unused object: you are finished using an object, but because one
or more other objects still reference that object, the garbage collector cannot reclaim its memory. The memory occupied by
that object is thus lost from the usable heap. These types of memory leaks typically occur during Web requests, and while
one or two leaked objects may not crash your application server, 10,000 or 20,000 requests might. Furthermore, most objects
that are leaked are not simple objects such as Integers or Doubles, but rather represent subgraphs within the heap. For example, you may inadvertently hold on to a Person object, and that Person object has a Profile object that has several PerformanceReview objects that each maintain sets of data. Rather than losing 100 bytes of memory that the Person object occupies, you lose the entire subgraph that might account for 500 KB or more of memory.
In order to identify the root of this problem, you need to determine whether a real memory leak exists or whether something
else is manifesting as an OutOfMemoryError. I use the following two techniques when making this determination:
The JVM tuning process is not the same for all JVMs, such as Sun and IBM, but some commonalities exist.
Sun JVM memory management
The Sun JVM is generational, meaning that objects are created in one space and given several chances to die before they are
tenured into a long-term space. Specifically, the Sun JVM is broken into the following spaces:
Figure 1 illustrates the breakdown of the Sun heap's generations and spaces.

Figure 1. The Sun JVM is partitioned into two major generations: the old generation and the young generation
Objects are created in Eden. When Eden is full, the garbage collector iterates over all objects in Eden, copies live objects to the first survivor space, and frees memory for any dead objects. When Eden again becomes full, it repeats the process by copying live objects from Eden to the second survivor space, and then copying live objects from the first survivor space to the second survivor space. If the second survivor space fills and live objects remain in Eden or in the first survivor space, then these objects are tenured (that is, they are copied to the old generation). When the garbage collector cannot reclaim enough memory by executing this type of minor collection, also known as a copy collection, then it performs a major collection, also known as a stop-the-world collection. During the stop-the-world collection, the garbage collector suspends all threads and performs a mark-and-sweep collection on the entire heap, leaving the entire young generation empty and ready to restart this process.
Figures 2 and 3 illustrate how minor collections run.
Figure 2. Objects are created in Eden until it is full. Click on thumbnail to view full-sized image.
Figure 3. The order of processing is important: The garbage collector first traverses Eden and then the survivor space; this ensures that objects are given ample opportunity to die before being tenured. Click on thumbnail to view full-sized image.
Figure 4 illustrates how a major collection runs.
Figure 4. When the garbage collector frees all dead objects and moves all live objects to a newly compacted tenured space, it leaves Eden and both survivor spaces empty. Click on thumbnail to view full-sized image.
From Sun's implementation of garbage collection, you can see that objects in the old generation can be collected only by a major collection. Long-lived objects are expensive to clean up, so you want to ensure that short-lived objects die in a timely manner before they have a chance to be tenured, and hence require a major garbage collection to reclaim their memory.
| Subject | Replies |
Last post
|
|
By Anonymous |
1 |
10/05/06 06:30 AM
by Anonymous |
|
By JavaWorld
|
0 |
10/05/06 06:17 AM
by JavaWorld |
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq