Friday, August 31, 2007

HTML menu DIV tag over a SELECT element

We are using a JS menu that used layers created by div tags. The problem was that this layer was hiding behind behind 'select' dropdowns in the page.

I googled around for a solution and found out 2 solutions:
- Hide the select boxes when the menu is clicked and unhide them when the menu rolls back.
- Use the zIndex property and create a transparent IFrame under the menu layer.

The following links were of great help to me:
BEA portal menu.
IFrame option.
Hiding option.

Wednesday, August 29, 2007

Heap size and Perm size

I was getting confused if the heap size specified by -Xmx included the Perm size or it did not? The GC document on Sun's site showed the Perm generation to be part of the Heap size, but I think this is wrong. It seems that the Perm size is different from the Heap size. I found this link that confirms this belief.

The "permanent" generation in the Sun JVM is for class objects, method objects, static fields for those classes (just the static fields, not the objects referenced from the static fields: those are in the regular Java object heap because Java code allocates them), and random other bits like any interned Strings etc. So if U are using a lot of reflection in you code, then a lot of method objects and class objects are created at runtime. For e.g. XML binding frameworks such as Castor etc. use reflection by default.

Hence the total heap size used by the JVM is the Permanent Generation size + the -Xms/Xmx size.

The total memory used by the JVM process will be = Memory used by the JVM for internal management + memory allocated in native code + memory allocated for the permanent space.
This is the memory that U see in Task-Manager in Windows or 'top' on Solaris.

What happens when we allocate more Java heap than the max physical memory available?
The OS would start swapping the process to disk (depending on the Virtual memory configuration) if the total memory reserved by all applications and the OS in the system exceeds the physical RAM installed. This would seriously degrade the performance of the system.

*IMP*: If your application is throwing an OutOfMemoryError then it could be because the PermSize is full, rather than the heap size.

Saturday, August 18, 2007

HttpClient in a multi-threaded environment

Our application was using HttpClient library to connect to various third-party systems. I was proposing to develop a smart resuable component that could be used by other modules and also suffice the performance requirements of the application.

I was joyed to see how the design of HttpClient offers excellent support for multithreaded environments.
The HttpClient and ConnectionManager classes can be shared across the entire application. Each respective thread of execution must have a local instance of HttpMethod and can have a local instance of HttpState or/and HostConfiguration to represent a specific host configuration and conversational state.
Hence these must be local variables in all the methods. At the same time the HttpClient instance and connection manager are shared among all threads for maximum efficiency.

If an proxy configuration is required, then this information can be passed in the execute() method of PostMethod using the HostConfiguration class.

Wednesday, August 15, 2007

Finding the version of Solaris

Commands to find out the version of Solaris the box is running on:
uname -X
more /etc/release

Wednesday, August 08, 2007

Viewing large files on Linux/Solaris

Log files of J2EE applications can become very big. In our application, the log files were of the size ~ 700 MB to 1GB.
To search such big files for information the following unix commands can be used:
- less fileName.txt
To search a string in the forward direction
- /searchString
To move to the next search
- n
To search backwards
- ?searchString

Javascript goodies

Today, I spend quite some time refactoring messy Javascript code:

1.) I needed to extract a number appended to the end of the string - use the power of regular expressions to make this one clean and sleek.
var RowIdNumber = rowId.match(/\d+$/)[0];
2.) To obtain a 'anchor' element inside of a table row and invoke it's click (href) -
Enjoy :)