Exercise 1.2: Collecting thread data
Before you begin, you must complete Exercise 1.1: Importing the required resource.
Scenario: The program that you will be investigating runs briefly, and then abruptly comes to a halt. This happens every time you run them program. This behavior is typical of thread deadlocks, so you are asked to investigate how the threads in this program interact.
To locate possible thread deadlocks, you will first collect thread data. and then analyze the data using the Thread View in the Profiling and Logging perspective.
Collecting thread data will allow you either to identify the deadlock or to rule out threads as the cause for the application's failure.
Preparing to collect thread data
To collect thread data, you must be in the Profiling and Logging perspective.
To switch to the perspective:
- From the Software Development Platform menu bar, select Window > Open Perspective > Other... The Select Perspective dialog box opens.
- In the lower left of the dialog box, click Show all. A check appears in the check box.
- From the list of perspectives, select Profiling and Logging and click OK.
- If the Confirm Enablement dialog box opens, click Always enable capabilities and don't ask me again, and then click OK.
- The Software Development Platform switches to the Profiling and Logging perspective.
Collecting thread data for the philosopher application
To collect data:
- From the Software Development Platform menu bar, select Window > Show View > Console to open the Console view. The Console view allows you to follow the application as it processes.
- Create a profiling configuration:
- From the menu bar, select Run > Profile... The Profile dialog box opens.
- In the Configurations list, double-click the Java Application entry. A New_configuration entry appears.
- In the Name field, type PhilosopherThreads.
- In the Main tab, if philosopher is not already entered in the Project field, do the following:
- Next to the Project field, click Browse. The Project Selection dialog box opens.
- Select philosopher and then click OK.
- Next to the Main class field, click Search.
- In the Choose Main Type dialog box, select MaitreDHote, and then click OK.
- If you are using the IBM Java virtual machine (JVM), do the following:
- In the Profile dialog box, click the Arguments tab.
- Under VM arguments, type -Xj9 to specify the correct JVM version.
- In the Profile dialog box, click the Profiling tab.
- In the Overview sub-tab, check the check box for the Thread Analysis profiling set. (A profiling set defines the type of profiling data that is to be collected for the run.)
- Click Profile. The application runs, and the display changes as follows:
- A Profiling resource appears in the Profiling Monitor.
- The Console view shows the output for the run.
Note: If you get a Security Message that Agent Controller is not available, read If you were unable to collect data.
When the application reaches a certain point, it stops processing. The output looks something like this:
. . .
philo#3: waiting for right fork#3
philo#2: waiting for right fork#2
philo#1: waiting for right fork#1
philo#0: waiting for right fork#0
HeadWaiter: all philosophers are locked for 6 times.
exiting application.
This is where the program stops. For this run, however, you have collected thread data, and you can now analyze why it has stopped.
If you were unable to collect data
Before you can collect any kind of profiling data, Agent Controller must be running. If you get a message that Agent Controller is not available, make sure that Agent Controller has been installed, start it manually, and try again. For instructions, refer to the installation guide. You can access the installation guide by using the launchpad, or you can find it on the product CD under disk1/install.html.
After you collect data, you are ready to begin Exercise 1.3: Identifying a thread bottleneck.