Create a Threads package under your Labs project. Create all your Java code for
ID: 3758071 • Letter: C
Question
Create a Threads package under your Labs project. Create all your Java code for this lab in that Threads folder.
#Build a class file called “LoopRunner.java”. This class should implement Runnable. When run, an object of this class will loop a number of times printing out a single character to standard out. For example the character ‘a’ 50 times. Use a constructor to pass in the character to be printed and the number of times to print it. You’ll have to store these values in local variables (why?). There is no main() method in this class.
#Build a class file called “Unit05_LabTester.java”. This class will create four threads (in addition to main()) and run a LoopRunner object on each of the four threads (can it be the same LoopRunner object, or will you need four LoopRunner objects? Why?). Each thread must use a different character for printing and print a different number of times. The main method of this program will print out to standard out the message “Main Thread here” after starting all four threads.
#Experiment – Run the Unit05_LabTester a number of times. Is the output the same every time? Why or why not? (no need to report this, but you should do it and think about the results).
Explanation / Answer
The following is the code implemented for a loop runner: