Tuesday, April 29, 2008

EJB 3 In Action Code Examples on WebLogic 10

In my previous blog, I made the code examples available for first four chapters of EJB 3 In Action for WebLogic 10. However I did not provide you instructions to run these examples (Chapter 2-4) for WebLogic 10.

Chapter 2 example has a stateless session bean, stateful session bean, an MDB and a JPA Entity. The JPA persistence unit requires a JDBC DataSource and the Stateful/MDB uses a JMS queue.

Chapter 3 depends upon a JDBC DataSource and Chapter 4 uses JDBC DataSource and a JMS Queue.

I’ve provided a build script to configure these resources on the default examplesServer that gets created when you install WebLogic 10.

  1. Download examples from here and unzip to a directory say c:\ejb3inaction\weblogic
  1. Set the environment variables for your server as follows:

%BEA_HOME%/wlserver_10.0/samples/domains/wl_server/setExamplesEnv

  1. Change to your directory to the directory

cd c:\ejb3inaction\weblogic

ant CreateResources

This will configure resources such as JDBC DataSource, JMS Connection Factory, Queues, etc.

4. To deploy the application, you can use WLS Admin Console. If you prefer you can use ant to deploy the application for a specific chapter.

cd chapter2
ant

  1. To run the application client:

ant run

Hope this helps! I'm working on porting rest of the examples and will make these available sooner.

Thursday, April 17, 2008

Diagnosing Production Java applications with AD4J

One of my applications that uses EJB 3 and JPA was running much slower today and I had no clue what was going on. It is a very simple application to manage service requests. When I was trying to update some data for a service request – it was taking ever. Also searching of service requests by some search criteria was taking much longer than it does.

So I thought I would give Oracle AD4J a spin and will try to find out what is going! It is good that Oracle AD4J does not require any code changes in application, because it does not use byte code instrumentation. Nor does it require to restart/redeploy the application – so it was a perfect fit.

And it really helped diagnose the problem by me get into bottom of the issues. It was indeed a DB issue as I had initially suspected.

I will not bore you with installation and configuration steps of AD4J – rather I will outline how AD4J helped me diagnose the issue.

Finding the Offending Thread

As soon as I logon to AD4J console and clicked to view active threads – it showed all threads with the correct state and I saw one thread is with status “DBWait”.





That gave me an indication that something going fishy in the database request from from JPA provider.

Finding DB issue

When I clicked on DB Wait link to view details, it became clear that the transaction is running into some row lock contention with another user session.




Finding the SQL statement

Interestingly it allowed to me to view the SQL Statement that is taking forever by clicking the SQL hash. My application uses JPA 1.0 and I could view the SQL statements causing problem without increasing the log level from my JPA provider as in the following figure:

It also helped me find the other session that held the lock. Apparently we found that it was a batch process that was hanging for some reasons. After the hanging session was killed the application ran like a champ again!

Also I found that the JPQL query for retrieving SRs was running slower because of some missing indexes on the column and it was making a full table scan. Nice, it also AD4J allows to run explain for sql statements.

Downloading AD4J

You can download AD4J from OTN (http://www.oracle.com/technology/software/products/oem/htdocs/jade.html)

Installing AD4J Console and agents

Installing AD4J Console is easy. You can follow this guide to do this installation of AD4J Console and agent.

After you deploy the agent you are good to go. Your JVM for application server will be automatically discovered in the console.

The AD4J agent is a WAR file that needs to be deployed to the server. You can follow the instructions in the install guide to install the agent in favorite application server. I was using my favorite container OC4J, however it supports BEA WebLogic, IBM Websphere, JBoss, and Tomcat. You can run AD4J also with standalone Java.

If you want to trace the problem to the DB tier you can install the DB Agent. You can follow the instructions in this guide.

I will play around with AD4J and blog little more about its feature in future. In the meantime you can review it's usage scenario documented in here.

Tuesday, April 15, 2008