Translate

Search This Blog

Wednesday, 22 June 2011

JVM

Java Virtual machine -is an abstract computing machine. It is the component of java technology that gives it hardware and OS independence. It has its own instruction set and manipulates various memory areas at run time.

The architecture as defined in the specification makes it possible to have different JVM implementation for different hardware platforms.The architecture of the JVM as defined in the specification is shown in the diagram below

It consists of
  1. Class Loader subsystem
  2. Run time data areas
  3. Execution engine
  4. Native method interface
  5. Native method libraries.
Class loader subsystem - is responsible for loading types (classes and interfaces). The .class files adhere to fix format and it contains JVM instructions or byte codes, a symbol table and other ancillary information.
Execution engine - is responsible for the actual execution of the instructions contained in the method of the loaded classes.
Run time data areas - the JVM organizes the memory it needs to execute a programs into various data areas. These various data areas may be shared by all the threads in the program or some data areas may be thread specific
  • The method area and heap is shared by all the threads
  • where as the PC registers,java stack, native method stack are thread specific.
Each instance of JVM has one memory area and one heap.
  • Method area: holds the details of each class loaded by the class loader subsystem.
  • Heap: holds every object being created by the threads during execution, including the main thread.

As each thread executes in the JVM, it gets its own PC register and the java stack. They are not shared among threads.

  • PC registers: For any executing thread the register holds the address of the next instruction to execute.
  • Java Stack: the stack stores the state of the method invocation (state - includes the local variables, the method parameters, the return value if any and intermediate or temporary calculations) of the thread (in stack frames - current execution method stack frame is the topmost)
  • Native method stack : the state of the native method are stored in native method stacks in an implementation dependent way, so also possibly the registers or an other implementation dependent memory areas.

More on class loader subsystem in my next blog.

You can find useful references


Java Platform

is a platform for java development. It is a software only platform which is ported on hardware platforms It comprises of two major components
  1. JVM - Java virtual machine - it is the component which add portability aspect to Java. JVM understand byte codes (compiled .class files from .java classes). Byte codes are the machine language of the JVM. JVM then interprets byte codes to the actual underlying machine language. Compilation happens only once and interpretation happens each time the program is executed.
  2. Java API - a set of classes written using java and which runs on the JVM. It consists of lot of useful classes which help us in development of applications etc.
You can find useful references

Sunday, 5 June 2011

Concurrent call exception using Seam and JSF

I got this exception, while working on a Ajax+JSF+Seam project. I ignored it for a while till it came back haunting at the UAT.
A little investigation into the exception and googling help me find the answer. Here is what happened, I had a ajax component which was taking a long time to render the response, in the meanwhile another request was sent to the server through some other component action ex a submit button, this call failed to render the response, reason being the first call had obtained a lock in the render_reponse and hadnt released it, so the second call failed to obtain a lock and hit back with the exception.
You could solve this in one of the following ways,
1. Showing a wait dialog so that the users understand that there is some processing going on.
2. queueing the request, a4j has a component named 'queue' which you can leverage.

If there are better ways to handle this, I will be glad to add it to my kitty.

Sunday, 6 December 2009

OSGi - introduction

OSGi - Open Services Gateway initiative helps to develop and deploy applications/libraries which are modular or need to be modular.This specification was started by OSGi alliance in 1999.
To develop OSGi application, the OSGi specification defines two things: first the set of services that the OSGi container needs to implement and second a contract between the OsGi container and the application. So in short, you need a OSGi container to run your OSGi complaint application. As of now there are 3 containers that are OSGi complaint; Knopflerfish,Equinox and Apache Felix.
OSGi offers several advantages
  1. one can install,uninstall,start, stop any modules of the application at runtime.
  2. Helps to build service-oriented applications
  3. Application can have more than one version of a module running at the same time.

In the next article I will show you how each of these advantages translates into code rather than just plain english sentences in your tech vocab.

Tuesday, 2 June 2009

NullPointerException in static factory-method in Spring

For one project, I was trying to test db connection at startup using some method like
ConnectionTest
{
public static void testConnection(DataSource ds){...}
..
}

which I happily configured in Spring using the factory-method attribute. To my surprise I got NullPointerException in populateMethod of Spring class AbstractAutowireCapableBeanFactory.

The reason for this was, Spring was expecting a object to be returned as it's a factory-method and fatory method will always return some object. Since my use case was to only test the connection and leave it I didnt return anything.

Hope this helps.

Monday, 1 June 2009

Binary To Text using Base64 encoding

If you need to convert binary data to text one of the recommended approach is to use base64 encoding and not direct string conversion like
byte[] byteArray = //get byte array from any image file
String str = new String(byteArray);

This is not recommended as it will not necessarily represent a valid character string in any encoding. Base64 will make sure that the byte array represents a valid ASCII character string
Ex byte[] byteArray = //get byte array from any image file
String str = new Base64Encoder().encode(byteArray);

To support this point lets take an XML String with the str String padded between some xml element like
String xmlString = <imagedata>;
xmlString+=str;
xmlString+=</imagedata>;

This xml when parsed for the image
InputSource inputSource = new InputSource(new StringReader(xmlString));
DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder();
Document document = builder.parse(inputSource);

will throw an error in the first case ie using String saying
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0) was found in the element content of the document.

So a cleaner approach is to use Base64 encoding.

Sunday, 10 May 2009

GWT

Was excited to check Google GWT 1.6, I decided to try an example application using the same. But hit a road block when I got stuck when I needed more advanced features, so had to look at ExtGWT or GWT-Ext, was confused as to what to use. GWT-Ext is maintained by Sanjiv Jivan and uses ExtJS, and ExtGWT (GXT) is from the makers of ExtJS.I decided to move on ExtGWT, I made this choice based on that I would always put a bet on some company product than an individual,purely my decision. Though, GWT-Ext seemed so viable and tempting option.