
CECS 327
Assignment 2 (5 points)
Due Wednesday, 9/17/08
The following Java application spawns three threads, each prints 10 lines on the standard output
device. Find out what the output is like when the program is executed, and comment what may have
gone wrong, if any, in the program design.
Requirements:
Demo program execution in lab on 9/17/08.
Hand in program listing, with output and explanation of program design flaw, if any.
/*
* Create and run 3 threads concurrently
* All try to output at the same time
*/
public class RunThreads {
public static void main(String[] args) {
Thread p1 = new Thread(new SomeThread(1));
p1.start();
Thread p2 = new Thread(new SomeThread(2));
p2.start();
Thread p3 = new Thread(new SomeThread(3));
p3.start();
}
} // end class RunThreads
class SomeThread implements Runnable {
int myID;
SomeThread(int id) {
this.myID = id;
}
public void run() {
int i;
for (i = 1; i < 11; i++)
System.out.println("Thread"+myID+": "+i);
}
} // end class SomeThread