samaxes

samaxes logo

Ramblings about Open Source, Java and other Web technologies by Samuel Santos

Install Internet Explorer 6 in Windows Vista

You probably have already heard about Yousif Al Saif’s Multiple IE installer which makes possible to run Internet Explorer 6 in standalone mode. The problem is that Multiple IE doesn’t work on Microsoft Vista (still you can use an Internet Explorer Application Compatibility VPC Image).

Hopefully Yousif Al Saif is making progresses in getting Internet Explorer 6 run natively under Windows Vista.

More news to come…

Open Source .NET Framework

Microsoft announced today the release of the .NET Framework source code under the Microsoft Reference License.

Find more about it.

Classloader leaks and PermGen space

After googling a bit for error “java.lang.OutOfMemoryError: PermGen space” I found many sites talking about that problem. Some tried passing command line arguments to the JVM or changing the size of the PermGen space, others end up recommending using a VM from BEA or IBM, all without success.

But after a closer look at their comments I ended up at Frank Kieviet blog.
Frank explains what really is a PermGen error

The problem in a nutshell

Application servers such as Glassfish allow you to write an application (.ear, .war, etc) and deploy this application with other applications on this application server. Should you feel the need to make a change to your application, you can simply make the change in your source code, compile the source, and redeploy the application without affecting the other still running applications in the application server: you don’t need to restart the application server. This mechanism works fine on Glassfish and other application servers (e.g. Java CAPS Integration Server).

The way that this works is that each application is loaded using its own Classloader. Simply put, a Classloader is a special class that loads .class files from jar files. When you undeploy the application, the Classloader is discarded and it and all the classes that it loaded, should be garbage collected sooner or later.

Somehow, something may hold on to the Classloader however, and prevent it from being garbage collected. And that’s what’s causing the java.lang.OutOfMemoryError: PermGen space exception.

PermGen space

What is PermGen space anyways? The memory in the Virtual Machine is divided into a number of regions. One of these regions is PermGen. It’s an area of memory that is used to (among other things) load class files. The size of this memory region is fixed, i.e. it does not change when the VM is running. You can specify the size of this region with a commandline switch: -XX:MaxPermSize. The default is 64 Mb on the Sun VMs.

If there’s a problem with garbage collecting classes and if you keep loading new classes, the VM will run out of space in that memory region, even if there’s plenty of memory available on the heap. Setting the -Xmx parameter will not help: this parameter only specifies the size of the total heap and does not affect the size of the PermGen region.

… and how to use new profiling tools in Java 6 to fix Classloader leaks.
Resuming, the steps are:

  1. start your application server
  2. deploy and run your application
  3. undeploy the application that is leaking (just the application not the server)
  4. trigger a memory dump jmap -dump:format=b,file=leak <PID>
  5. run jhat (with modification, Java SE SDK 6.0 update 1 has the updated code) jhat -J-Xmx512m leak
  6. go to jhat report http://localhost:7000/ (http://localhost:7000/oql/ if you need the OQL (Object Query Language))
  7. find a leaked class (any class of your application since you shouldn’t see any objects of the classes that you deployed)
  8. locate the Classloader
  9. find the “Reference chains from root set”
  10. inspect the chains, locate the accidental reference, and fix the code

Some try even to go further on finding Orphaned Classloaders others try to nicely present the leaking classes in a form of a HTML table histogram.

These tools can really help, use them!

Resources

Code conventions and programming style

Coding conventions are rules that computer programmers follow to ensure that their source code is easy to read and maintain.

Why is that important?

Sun Microsystems provides the following rationale for the Java Programming Language:

Code conventions are important to programmers for a number of reasons:

  • 80% of the lifetime cost of a piece of software goes to maintenance.
  • Hardly any software is maintained for its whole life by the original author.
  • Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.
  • If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.

Crossbow Software has gather a set of code conventions and programming style documents, take a look at their Coding Style Standards download page.

Microsoft Photosynth

Some great graphics technologies are emerging lately.

One that looks very promising is Photosynth from Microsoft Live Labs.

Photosynth takes a large collection of photos of a place or an object, analyzes them for similarities, and then displays the photos in a reconstructed three-dimensional space, showing you how each one relates to the next.


Earlier this year, Blaise Aguera y Arcas had demonstrated Seadragon and Photosynth at the TED (Technology, Entertainment, Design) Conference in Monterey.

Content Aware Image Resizing

Dr. Ariel Shamir and Dr. Shai Avidan of the Efi Arazi School of Computer Science have presented at SIGGRAPH 2007 the greater digital image effect I’ve seen.

“Seam carving” allows an image to be resized non-uniformly, so you can change the height to width ratio in the image without cropping.

The algorithm looks for seams (not simple columns or rows) of pixels with the ‘least energy’ (least contrast / change in detail) both vertically and horizontally in the image and then uses this to enable resizing without losing important image content such as human subjects or other detail.

This technique can also be used to manually remove items from the image which are not wanted as well as protect items that absolutely need to be preserved.

Get the Seam Carving for Content-Aware Image Resizing from Dr. Ariel Shamir and Dr. Shai Avidan. [20 MB PDF - very slow downloading]
Alternate locations at Corel Cache and ACM.

JBoss Web and PHP Install Tutorial

Approximately 2 years ago I’ve written a set of PHP Tutorials that served as a guideline for a Beginner’s PHP Training Course. These tutorials were made with the WAMP solution stack in mind.

Since I’ve been working with Java EE Technologies and Servers recently, I’ve decided do add another one explaining how to install JBoss Web 1.0.1 GA with PHP support (PHP Handler Servlet).

This was based on a tutorial by Philippe Fievet that is now offline for some reason.

Creating Offline Web Applications with Dojo Offline Tutorial

Brad Neuberg from Sitepen wrote an extensive tutorial about Creating Offline Web Applications with Dojo Offline.

What is Dojo Offline?

Dojo Offline is an open-source toolkit that makes it easy to create sophisticated, offline web applications. It sits on top of Google Gears, a plugin from Google that helps extend web browsers with new functionality. Dojo Offline makes working with Google Gears easier; extends it with important functionality; creates a higher-level API than Google Gears provides; and exposes developer productivity features. In particular, Dojo Offline provides the following functionality:

  • An offline widget that you can easily embed in your web page with just a few lines of code, automatically providing the user with network feedback, sync messages, offline instructions, and more
  • A sync framework to help you store actions done while offline and sync them with a server once back on the network
  • Automatic network and application-availability detection to determine when your application is on- or off-line so that you can take appropriate action
  • A slurp() method that automatically scans the page and figures out all the resources that you need offline, including images, stylesheets, scripts, etc.; this is much easier than having to manually maintain which resources should be available offline, especially during development.
  • Dojo Storage, an easy to use hashtable abstraction for storing offline data for when you don’t need the heaviness of Google Gear’s SQL abstraction; under the covers Dojo Storage saves its data into Google Gears
  • Dojo SQL, an easy to use SQL layer that executes SQL statements and returns them as ordinary JavaScript objects
  • New ENCRYPT() and DECRYPT() SQL keywords that you can mix in when using Dojo SQL, to get transparent cryptography for columns of data. Cryptography is done on a Google Worker Pool thread, so that the browser UI is responsive.
  • Integration with the rest of Dojo, such as the Dojo Event system

Dojo Offline is built to work with the 0.9 release of Dojo, and will not work with older versions of Dojo, such as 0.4. It also requires the Google Gears plugin to function; if users do not have it installed Dojo Offline will prompt users to download it.

SQL Server Paging

Paging with SQL Server has always been a pain. Although SQL Server 2005 introduced some features that made it possible to page results efficiently more easily than ever before.

Paging in SQL Server 2005 at 15 Seconds shows you how to do it with the new ROW_NUMBER() function.

Maven 2 Cobertura Plugin

The Maven 2 Cobertura Plugin web site lacks information to successfully generate Cobertura reports. Worse, some of the usage examples are incorrect and don’t work.

The most common problem when generating Cobertura reports is when the generated report shows 100% test coverage while in reality many of the classes don’t even have tests.

The following example shows how to configure the reports so that it would reflect real test coverage and then check if the specified packages achieved the wanted test coverage:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <check>
                    <haltOnFailure>false</haltOnFailure>
                    <regexes>
                        <regex>
                            <pattern>com.samaxes.business.*</pattern>
                            <branchRate>90</branchRate>
                            <lineRate>90</lineRate>
                        </regex>
                        <regex>
                            <pattern>com.samaxes.persistence.*</pattern>
                            <branchRate>90</branchRate>
                            <lineRate>90</lineRate>
                        </regex>
                    </regexes>
                </check>
                <instrumentation>
                    <includes>
                        <include>com/samaxes/**/*.class</include>
                    </includes>
                </instrumentation>
            </configuration>
            <executions>
                <execution>
                    <id>clean</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>instrument</id>
                    <phase>site</phase>
                    <goals>
                        <goal>instrument</goal>
                        <goal>cobertura</goal>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
</reporting>

Sponsors