For Complete Source Code Contact Me On WhatsApp +923054957063
OR email : [email protected]
Title: “Project 2: Multi-threaded Programming in
Java”
Objectives: To practice programming an application
with multiple threads of execution and synchronizing
their access to shared objects.
Most Class 1 (BNSF, Union-Pacific, CSX, Norfolk-Southern) railroads in the United
States today, use a train scheduling technique known as Precision Scheduled Railroading (PSR). In
the past, the USA rail service model focused on moving long trains in order to maximize capacity and
yield the greatest efficiency. This technique however, did not always yield the best outcome for either
the railroad or its customers. Since the railroads aimed to build trains that would move faster, if a
train didn’t meet a specific length requirement, it could be cancelled (annulled in railroad lingo). This
would often leave the customer without service for the day.
Every train yard has a unique track/switch alignment configuration, so we are only simulating this
particular track/switch arrangement. Even within this fairly simple yard arrangement, there are
multiple possibilities for track/switch alignments. Your application does not need to handle random
or unknown configurations. The configuration you are simulating is shown above and consists of
eight (8) separate tracks, four on each side of the yard and five switches that allow the various tracks
to be aligned. A specific configuration for the switchyard is held in an input file (see below).
As stated above, a train cannot begin moving through the yard until it controls all of the switches that
it needs to move from its inbound track to its outbound track. Until a train obtains control of all of
the switches that it needs to move through the yard, it will remain idle on its inbound track. To
prevent switch control deadlock from occurring, every train must acquire the switches it needs in the
order of first switch required, second switch required, third switch required. At any point in
time during a train’s switch acquisition phase, if a required switch is not available, the train must
release all of the switches that it currently controls and wait some period of time before trying again.
You must use a the java.util.concurrent.locks.ReentrantLock interface. In
other words, do not create your own locking system nor implement a Boolean semaphore-like
system to control the locking.
3. Do not use a monitor to control the synchronization in your program (i.e., do not use the Java
synchronize statement).
4. You must use an ExecutorService object to manage a FixedThreadPool(MAX),
where MAX is the upper limit on the number of trains in a fleet, which we’ll set to be 30 (see
below under Input Specification).
5. Your Train threads must implement the Runnable interface and not extend the Thread class
in order to utilize the ExecutorService object mentioned in 4 above
theFleetFile.csv and theYardFile.csv as each are described above. You can assume
1. When a train obtains the lock on a needed switch:
Train #: HOLDS LOCK on Switch #.
2. When a train is unable to acquire the lock on the first required switch:
Train #: UNABLE TO LOCK first required switch: Switch {first}. Train will wait…
3. When a train holds the lock on the first required switch but cannot acquire the lock on the
second required switch:
Train #: UNABLE TO LOCK second required switch: Switch {second}.
Train #: Releasing lock on first required switch: Switch {first}. Train will wait…
4. When a train holds both the first and second required switch locks but cannot acquire the lock
on the third switch:
Train #: UNABLE TO LOCK third required switch: Switch {third}.
Train #: Releasing locks on first and second required switches: Switch {first} and Switch {second}.
Train will wait…
Page 5
5. When a train has obtained all required locks required to move through the yard:
Train #: HOLDS ALL NEEDED SWITCH LOCKS – Train movement begins.
6. After event #5 above has occurred (after a suitable time to simulate the time required to move
the train through the yard):
Train #: Clear of yard control.
Train #: Releasing all switch locks.
Train #: Unlocks/releases lock on Switch {first}.
Train #: Unlocks/releases lock on Switch {second}.
Train #: Unlocks/releases lock on Switch {third}.
Train #: Has been dispatched and moves on down the line out of yard control into CTC.
@ @ @ TRAIN #: DISPATCHED @ @ @
7. When a train’s inbound track to outbound track does not match any allowed switch
configuration in the train yard:
*************
Train # is on permanent hold and cannot be dispatched.
*************
8. As the simulation begins:
$ $ $ TRAIN MOVEMENT SIMULATION BEGINS……….. $ $ $
9. After all trains, not on permanent hold have been dispatched:
$ $ $ SIMULATION ENDS $ $ $