Lab10: Threads

This is a simple lab to demonstrate the most basic threading implementation. You can easily write this lab in 30 lines or less.

We will write a method that counts from 0-4, then we will run several threads of that method simultaneously.

This lab will not deal with any of the potential problems caused by concurrency. We can revisit those problems once we have first implemented the basics.

The Assignment

You are going to create a Lab10 class with the following requirements:

Sample output

$ java Lab10 3
0
0
0
1
1
1
2
2
2
3
3
3
4
4
4

$ java Lab10 99
0
0
0
0
0
0
0
0
...

$ java Lab10
Usage: java Lab10 <number of threads>

$ java Lab10 asdf
Usage: java Lab10 <number of threads>
Could not parse: 'asdf'

Example of incorrect output

If you see this, you did something wrong...

$ java Lab10 3
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4

What to hand in

Lab10.java

Your file must be in a directory named 'Lab10'

Delete any *.class or other unneeded files prior to submitting

When you run the submit script, the directory and its contents get zipped and sent to your instructor. Ask for help early if you are having problems running the submit script.

Make sure that you run the correct submit script for your instructor: