Lab 11: Concurrency

À quelle heure le train arrive-t-il ?

--One of the four phrases I remember from my month listening to "Learn French in your Car" tapes.

The goal of this lab is to practice using concurrency.

1. Introduction and set up

You will be working with a train simulation. There are two trains running on elliptical tracks that meet at four points. In the code as you get it, they will (almost certainly) crash at the crossings. You need to modify the code so that they do not crash.

Make a new directory for this lab and copy the files that I am giving you.

cp -r ~tvandrun/Public/cs245/lab11/trains .

Then open the files Train.java, Track.java, and TrackPosition.java. (I do not recommend using Eclipse for this, since I've provided a bunch of classes with the compiled version only, which Eclipse doesn't approve of.)

2. Your task

Try running the program as it is and confirm that the trains crash.

Then fix it. All the coding you need to do is in Train.java. All you need to know about the rest of the code you can learn by looking at the interfaces Track.java and TrackPosition.java. The only new thing you need to know about Java is how locks, monitors, and synchronized stuff works.

Trains take up six track positions at a time---but since they are moving, it's often a good idea to give them a little space.


Thomas VanDrunen
Last modified: Wed Nov 7 10:51:58 CST 2012