CS 322 Fall 2013
Lab 4
Java Threads
JStack
Due Wednesday, October 9 at 10:00 P.M.

Please type up your answers in a simple text editor such as Emacs or vi and submit them on Moodle before the deadline.
Begin your answers by writing your name, the version and vendor of the JRE and the processor type and number of cores you are using to complete this exercise.

Thread are an important feature of most modern operating systems. In any Java program different threads are running, many of which you, the programmer, did not explicitly created.
In this lab you are asked to explore the threads that exist in Java programs.

Setup

Copy the following folder from royal

		/Shared/cs322/public/lab4
The directory includes two subdirectories each of which contains a set of *.class files for a simple game, the SilverGame. One folder has a text version of the game, the other has a graphical version.

The text-based version of the game runs by typing a command like the one below to the shell

java MyGame  10 6
The graphical game runs with
java MyLab 10 4
The first integer, which specifies the number of squares on the board is required; the second integer, which specifies the number of coins, is optional. An alternative to ps for finding the pid of a running Java program is jps -l, which lists all Java process ids.

Part I: jstack on Silver Games

jstack is an Unix command (available on Mac OS X) that "prints Java stack traces of Java threads for a given Java process" (man page).

Use jstack to trace the stacks of running Java threads

You are expected to read the man pages and online documents (see suggested resources below) to discover useful Java VM options, how jstack works and how to analyze the thread trace output.

Answer the following questions.

Part II: jstack on your own program

  1. Select a Java GUI program you have written, preferably one that runs as an Applet or JWS. Describe the program you choose to explore in your write-up.
  2. Run jstack on your running program. Do you see anything beyon what you saw in Part I? Report anything that is new.

Part III: jconsole

JConsole graphical user interface is a monitoring tool. The jconsole command launches "a graphical console tool that enables you to monitor and manage Java applications and virtual machines on a local or remote machine" (jconsole man page).
Use it to explore the graphical Silver Game process. Download the following plugin for the jconsole. Launch jconsole using the plugin to monitor the graphical Silver Game process.

Resources

The following links contain suggested readings.