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
- in each of the two versions of the silver game
- with and without the
VM
option -XX:+UseSerialGC
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.
- How many threads are running for each of the four cases above
text/graphics, with/without the VM option?
- Explain the differences in number of threads between the text-based and
the graphical versions.
- Explain the difference with and without the VM option -XX:+UseSerialGC.
(Without the VM option, the default GC setup is used.)
- Which thread types are part of the JVM? Describe their function.
(Other threads are from the running Java application.)
Part II: jstack on your own program
- 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.
- 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.
- What extra information does jconsole give beyond the threads stack trace
you saw previously? Why do more threads exist?
Download the following plugin
for the jconsole. Launch jconsole using the plugin to monitor the graphical
Silver Game process.
- Observe the Top threads pane while going back and forth between playing the
graphical game and observing jconsole. Describe the changes in most CPU usage that you observe.
Resources
The following links contain suggested readings.