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.
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 127.0.0.1, change your /etc/hosts file according to this example:
192.168.2.200 myserver myserver.mydomain 127.0.0.1 localhost localhost.localdomain ::1 localhost6 localhost6.localdomain6
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"> <a4j:outputPanel> <h:graphicImage value="path-to-bullet"/> <rich:toolTip> <rich:message for="#{field}"/> </rich:toolTip> </a4j:outputPanel> </f:facet> </rich:message>
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.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.