Extreme Java When vanilla Java is not enough


Using cache for WordPress

Due to server overload whenever a bot searches my blog, I decided to configure a caching mechanism on my WordPress. Ease as 1-2-3: just install the plugin, configure it (I'm using Amazon CloudFront as CDN), preview and deploy.

Filed under: Uncategorized No Comments

Strange bug connecting to JMX

Small tip: if your JMX-enabled application runs on Linux, make sure your /etc/hosts is well configured. Failing to do so will lead to strange remote connection errors on JConsole or similar.

Test your configuration with "hostname -i". It must show server's IP. If it shows, change your /etc/hosts file according to this example:  myserver     myserver.mydomain      localhost    localhost.localdomain
::1            localhost6   localhost6.localdomain6
Filed under: Uncategorized No Comments

Marker-only validation error with RichFaces

I've made a simple JSP 2.1 tag file to show only a small icon on my validation errors (and a tooltip to show message details). This is the .tag file:

<%@ tag pageEncoding="UTF-8" %>
<%@ attribute name="field" required="true" deferredValue="true" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<rich:message for="#{field}" showSummary="false" showDetail="false">
  <f:facet name="errorMarker">
      <h:graphicImage value="path-to-bullet"/>
        <rich:message for="#{field}"/>

It can be used like this:

<tags:errorMessages field="id-of-the-field"/>

Instead of showing a big chunk of text, your webdesigner will only deal with a small bullet that will show a nice tooltip with the full message. Some "catches":

  • <rich:message tooltip="true"> does not show tooltip if you disable both summary and details;
  • Since "rich:toolTip" can't work with "h:panelGrid", the "a4j:outputPanel" will show the tooltip without adding any extra visual effect (like "rich:panel" does);
  • The inner "rich:message" will render the message inside the tooltip (notice that outer "rich:message" renders only the marker, because summary and details are "off").

Java remote debugging

This one was evil. I have an Windows XP box with a Virtual Box installed and a virtualized Xubuntu. I have a Java process running on Windows and my NetBeans is on Xubuntu, and I wanted to debug that Java process. An ugly problem, but it was really easy to solve. I've just added this option to the process JVM parameters:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=6543,server=y,suspend=n

After this, I can use NB's "Attach Debugger" feature to connect to the remote JVM. Works like a charm!


java.lang.OutOfMemoryError: Java heap space

Another easy one that I always forget the recipe. If a Java-based application throws a OutOfMemoryError, you can solve the problem by giving it more memory. Just pass one of these command-line arguments to java.exe:

  • -Xms256m - Java VM will start with a heap of 256mb.
  • -Xmx512m - Java VM will have a maximum heap of 512mb.
  • -XX:PermSize=128m - The permgen space will start with 128mb. This is needed when application instantiates a lot of small objects. It can be explained as the "FAT" (or "EXT3") of the objects.
  • -XX:MaxPermSize=256m - The permgen space will have a maximum of 256mb.