AppPerfect

Java Thread Profiling

This tutorial provides instructions on how to use AppPerfect Java Profilerproduct for detecting monitor
contention and possible race conditions in a java application. This tutorial assumes you have successfully
downloaded and installed AppPerfect Profiler on your machine with the default options.

Within each section, multiple exercises are listed. All exercises assume you have installed
the product in C:\AppPerfect\Profiler folder and will be referred as Profiler_HOME
henceforth in tutorial. If you have installed the product in some other folder, modify the instructions
below appropriately.

For this tutorial, create a java file called 'MonitorContention.java' copy-pasting the
code shown below and compile it.

Creating Project

Exercise 1: Launch AppPerfect Java Profiler

On launching AppPerfect Java Profiler a Welcome page will be displayed. Go through the brief description
given for product.
NB: Welcome page is displayed only when Profiler x.x.x is launched and last time no project
was opened.

Exercise 2: Creating a Project

Launch the Project Wizard by clicking File ->New... menu option.
The New Project wizard will be launched.

Go through the instruction provided on top of the General tab.

Keep the default project name and location for the purpose of this exercise. We don't have to provide
"Notification" settings or "Target Application Machine" settings for this exercise.
Click on the Next button.

In the Import tab do nothing. Click the Next button.

In the Source tab provide the location of source file "RaceCondition.java". Click the Next button.

Use the default JDK which is bundled with AppPerfect Java Profiler and click on the Next button.

In the "Environment" tab provide the location of "RaceCondition.class" file.

Click on "Verify Classpath" button to validate the classpath.

Classpath validation dialog will be launched and the classpath will be verified. A message saying
that the classpath specified is correct should be displayed. Click on the "OK" button.
Click on the Next button.

A confirmation message saying that the project is saved will be displayed. Click on the OK button.

AppPerfect Java Profiler

NB: Please follow the steps provided in the "Creating Project" section to first create a Project,
then proceed further.

Exercise 1: Define a Java Profiler project

Once the Project is successfully created another dialog - Define Project Properties dialog -
will be displayed.

Read the instructions at top of each tab.

Go through the descriptions for Profiling Types. Keep the default Development Mode Profiling and
select Profiling Options tab.

Study the descriptions of the three profiling options. You can configure Filters using Configure Filters
option. Use default values.

Study the descriptions of Instrumentation Options. Use the default: Dynamic Instrumentation enabled.

Click through all the menu items to familiarize yourself with the available features and
how to access them.

Click on Tools ->Options... menu item. Click on the "Browsers, JDKs & DBs" node and ensure that the JDK path has
been set correctly. This is the path provided for JDK during installation of AppPerfect Java Profiler. You may
modify the path or add new JDK through this dialog box. It is critical that a correct version of JDK is
available for AppPerfect Java Profiler to perform correctly.

Exercise 2: Start Profiling

A progress message will be shown while target application is launched.

Observe the dynamic updation of data in the default Project Summary view. You can see various profiling
metrics such as heap memory usage, object instance count and Thread count.

From the Navigational Tree select Monitors node.

On the right hand side, in the monitors tab you will see that there are 3 wait
counts on the particular monitor and that the wait duration is inecreasing.

Double click on row having Monitor ID 1; in the Details tab, and you will see that
Thread-0 and Thread-1 waited on the same monitor at the same time for the same amount of
duration. This is a sign of a possible race condition. Also you will see that
Thread-1 again waits for a longer duration this time indicating a high monitor contention.