My First Flyer

Analyzing thread dump for your Java application

Is your J2EE application responding slowly ? Is it getting hanged every now and then ?

The best way to start is take thread dump whenever you think performance is not to up to the mark and then analyze it.

Taking Thread Dump:

On unix system , you just have to first find out PID of your java process. You can use PS –alf | grep –in ‘java’ to find out the same.

Once you have PID, simply execute Following command:

 kill -3 PID

This will inform JVM to take current snapshot. It will be then copy to your standard log file/stdout file.

On windows, you have to execute ctr-break on the command prompt.


Analyzing Thread Dump:

If you don’t have right to tool for this, then it’s very hard to grasp what’s going on. I have used TDA http://www.ohloh.net/p/tda . This one is very nice, simple, easy and free tool. Once you open your log file (containing dump) in this tool, it will show all threads in tree structure, along with details of each thread. Most important of it is the thread state which could be like runnable, wait, wait on monitor, wait on conditions etc. Also it will show sleeping and locking threads separately. This will help you to identify the object on which threads are waiting and thereby identifying bottleneck in the system.

It has one feature to compare multiple thread dumps. It helps in finding out long running threads instantly.

If you have set -XX:+PrintClassHistogram JVM option while starting it, in thread dump it will also provide information of number of instance create for each classes along with the total bytes required for those objects. This should give you a fair idea of what classes and which modules are the one to look first for the optimization.


Rahul Ner

(RNer)

Creating web service from java class using Axis

Axis provides excellent platform for web service creation and deployment. Let's say you have a plain java class that you would like to expose as a web service. You can achieve this in few minutes. I assume here axis.war is already deployed on to your app server.

1. Create your java class with the method that you want to expose. (Its not web service aware.. so you don’t need to implement any interface etc.)

2. Now, register your web service with Axis. Simply add entry following entry to axis.war\WEB-INF\server-config.wsdd.

 <service name="WebServiceDemo" provider="java:RPC">

                       <parameter name="className" value="test.wbservice.Demo"/>

  <parameter name="allowedMethods" value="*"/>

                                           <parameter name="wsdlTargetNamespace" value="http://test.wbservice"/>

                                                                                </service>

 

 Class Name is fully qualified name of the class created in step 1. Now copy demo.class file to axis.war\WEB-INF\lib. If you prefer, You can create jar file containing this class and copy that to lib directory.


3. Restart your app server

4. Now you have deployed web successfully. You can check that using http://appsever_url/axis/services/webserviceDemo

    You can generate WSDL file containing all information of your web service using  http://appsever_url/axis/services/webserviceDemo?wsdl

5. Now You can generate client side stubs and classes required using WSDL2Java tool provided by axis.

   You have to execute this class passing wsdl to it.

java -cp axis.jar;commons-discovery.jar;commons-logging.jar;jaxrpc.jar;saaj.jar;log4j-1.2.8.jar;xml-apis.jar;xerces.jar;wsdl4j.jar org.apache.axis.wsdl.WSDL2Java   http://appsever_url/axis/services/webserviceDemo?wsdl


This will create all required file at the client side.


6.Generate client

        DemoServiceLocator demoLocator  = new DemoServiceLocator ();

       Demo demo = demoLocator .getWebServiceDemo();

        Demo.call_your_method()


Rahul Ner

Asset Depreciation query

SELECT temp.*, (COST - acc_dcost) final_cost
FROM (SELECT asset.code, deprec.yr, COST, deprec.dcost dcost_year,
SUM (dcost) OVER (PARTITION BY deprec.code ORDER BY yr)

acc_dcost
FROM (SELECT 1003 code, 10000 COST
FROM DUAL) asset,
(SELECT 2001 yr, 1003 code, 163 dcost
FROM DUAL
UNION ALL
SELECT 2002, 1003, 161
FROM DUAL
UNION ALL
SELECT 2003, 1003, 158
FROM DUAL) deprec) temp