Practice Assignment 2 - Net-centric Computing | CECS 327, Assignments of Computer Science

Material Type: Assignment; Class: Net-centric Computing; Subject: Computer Engr & Computer Sci; University: California State University - Long Beach; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-cpk
koofers-user-cpk 🇺🇸

7 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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

Partial preview of the text

Download Practice Assignment 2 - Net-centric Computing | CECS 327 and more Assignments Computer Science in PDF only on Docsity!

CECS 327

Assignment 2 (5 points)

Due Wednesday, 9/17/

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