Thursday, May 17, 2012

RowIdTableDecorator for Display Tag

/**
 * RowIdDisplayTagDecorator.java

 * Creation Date: May 16, 2012
 */
package com.kalai;

import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.displaytag.decorator.TableDecorator;

/**
 * RowIdDisplayTagDecorator is an extension of displaytag library's TableDecorator. When DisplayTag table in jsp makes use of this decorator, generates the row id
 * appending the columns that are configured on the displaytaguniquecolumns.properties with property key columns and values separated by ~ . <br>
 * Examples <br>
 * [displaytaguniquecolumns.properties - columns=column1~column2]<br>
 * [Lets say the column values for column1 and column2 are col1value and col2value respectively, than the row generated for the table looks like &lt;tr
 * id="rowcol1valuecol2value"> ] <br>
 * [if configured columns are not evaluated, it generates row id with index &lt;tr id="row0">, &lt;tr id="row1">]
 *
 * @author (Kalai)
 *
 */
public class RowIdDisplayTagDecorator extends TableDecorator
{
  private static String[] iUniqueColumns = null;
  private static Logger sLogger = Logger.getLogger(RowIdDisplayTagDecorator.class);

  /**
   * Loads the properties file that has the unique columns that makes a row uniqueness on the html table during inspection of the table
   */
  static
  {
    Properties displayUniqueColumnProperties = new Properties();
    try
    {
    
      InputStream propertiesFileStream = RowIdDisplayTagDecorator.class.getClassLoader().getResourceAsStream("displaytaguniquecolumns.properties");
      displayUniqueColumnProperties.load(propertiesFileStream);
      String columnvalues = displayUniqueColumnProperties.getProperty("columns");
      if (StringUtils.isNotBlank(columnvalues))
      {
        iUniqueColumns = columnvalues.split("~");
      }

    }
    catch (Exception exception)
    {
      sLogger.error(exception.toString());
    }

  }

  @Override
  /**
   * Adds the row id the the current row object using the columns configured to identify row uniquely to enable html table inspection based on row id
   * If no columns configured, it generates id indexed from 0 - size of the table rows
   */
  public String addRowId()
  {
    StringBuilder builder = new StringBuilder("row");
    try
    {
      for (String column : iUniqueColumns)
      {
        builder.append(evaluate(column).toString());
      }

    }
    catch (Exception exception)
    {
      sLogger.error(exception.toString());
      builder.append(Integer.toString(getListIndex()));
    }
    return builder.toString();
  }

}

Wednesday, February 22, 2012

Checking Java Heap and Thread Dumps in Unix / Solaris

Heap Dump

JAVA_HOME/bin/jmap -heap:format=b ******

where ****** is process id
Attaching to process ID *****, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 1.5.0_12-b04
Free chunk in heap, size=131072
Free chunk in heap, size=792741552
Free chunk in heap, size=148364752
Unknown oop at 0x00002aaafab6b6a8
Oop's klass is 0x00002aab06801de8
Finding object size using Printezis bits and skipping over...
heap written to heap.bin
It generates file “heap.bin”


Thread Dump
kill -QUIT ******


Thread dump appends info to already existing stdout logs usually in tomcat server

 Heap Dump : Another way

/usr/java/jdk1.5.0_12/bin/jmap -dump:format=b,file=heap.bin <pid>

The –heap option below prints a heap summary.  Not sure we want that in combination with the format=b.  When I ran the command below locally on my eclipse instance, it took about 5 mins to generate the heap.  When I used the command above it only took about 5 seconds.  Both heap dumps created seem valid, but according to the Usage guide –heap doesn’t have options with it, so not sure what the command is doing and the fact that it is taking a long time may be why you saw it puke.

Anyone else have some feedback on the command?

Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -permstat            to print permanent generation statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system
 

Wednesday, February 1, 2012

J2EE Connection Pooling

Why its so important?

Good managed connection pooled system are more scalable and reliable.


What level of an Enterprise application can this be applied?


Generally enterprise applications are n-tiered (UI Layer, middleware layer, Persistance Layer). Middleware layer can be attributed to a EJB, JMS/QUEUING Layer etc. Applying/Managing connection pooling in a more managed way at all these layers establishes a well scaled/ more reliable application.


How can it be achieved?
There are connection pooling factory mechanisms provided by the vendor (IBM, Oracle...)implementations for the products that integrate together for an enterprising solution.


Here is a very good article.
Dive into connection pooling for a J2EE Enterprise application

Sunday, January 29, 2012