Академический Документы
Профессиональный Документы
Культура Документы
Note: Units that are used in pairs count as 1, meaning that 2 hands =
1 head when counting surplus.
When a truck delivers parts it gets in line with other trucks.
Note: The line can be simulated using java.util.Vector. Since Vector is
already synchronized, we do not need to synchronize when
removing/inserting elements.
When the first truck in line moves to factory, it is told if its part is
considered to be surplus. If it is surplus, the truck decides to go at the
end of the line and retry. It also allows some incoming new trucks to
get on the line first (use yield ()). If a truck is on its second attempt
to get its part accepted by the factory, it is accepted, even if it is still
surplus.
When a manufacturer gets halted, it halts for time HALT_TIME (the
default is equal to PRODUCTION_TIME_MAX). Any other truck that
comes back from the factory and announces that manufacturer's part
is still surplus doesn't have any effect while manufacturer is halted.
The factory runs for time OPERATION_TIME. When the time left for
the operation equals OPERATION_TIME/5, each manufacturer is
announced about it in sequence. The order of sequence is from the
manufacturer that needs the parts the most, to the one that needs the
parts the least. Use join() to achieve proper sequence; isAlive() is
not really needed here since the factory will tell what to join, and
which manufacturer threads are still alive at that time. However will
be interested to use it in your implementation.
Note:
As an example, assume manufacturer M is needed most. It doesn't
join any other thread and continues to produce parts. Manufacturer
M1 that is needed less than M, joins M and, so on.
( M2 joins M1,..., MN joins M(N-1)).
Factory:
public synchronized boolean acceptPart( Truck truck ) {
/*
* write code to see if truck carries part that is surplus. Skip
* this part if truck is retrying - just accept.
*
* write code to update factory inventory of parts
*/
}
Manufacturer:
public synchronized void setIsSurplus( boolean isSurplus ) {
// write code
}
public synchronized boolean isSurplus() {
// write code
}
public synchronized void factoryIsAboutToStopOperation
( Manufacturer manufacturerToJoin ) {
// write code
}
public synchronized boolean isFactoryAboutToStopOperation() {
// write code
}
Guidelines
1. Do not submit any code that does not compile and run. If there are parts
of the code that contain bugs, comment it out and leave the code in. A
program that does not compile nor run will not be graded.
2. Follow all the requirements of the Projects description.
3. Main class is run by the main thread. The other threads must be manually
specified by either implementing the Runnable interface or extending the
Thread class. Separate the classes into separate files. Do not leave all the
classes in one file. Create a class for each type of thread.
4. The program asks you to create two different types of thread. A type can
have more than one instance of the thread.
12. Javadoc is not required. Proper basic commenting explaining the flow of
program, self-explanatory variable names, correct whitespace and
indentations are required.
Tips:
-If you run into some synchronization issue, and don't know which thread or
threads are causing it, press F11 which will run the program in debug mode.
You will clearly see the thread names in the debug perspective.
Setting up project/Submission:
In Eclipse:
Name your project as follows: LASTNAME_FIRSTNAME_CSXXX_PY
where LASTNAME is your last name, FIRSTNAME is your first name, XXX is
your course, and Y is the current project number.
For example: Fluture_Simina_CS340_p1
To submit:
-Right click on your project and click export.
-Click on General (expand it)
-Select Archive File
-Select your project (make sure that .classpath and .project are also
selected)
-Click Browse, select where you want to save it to and name it as
LASTNAME_FIRSTNAME_CSXXX_PY
-Select Save in zip format, Create directory structure for files and also
Compress the contents of the file should be checked.
-Press Finish
Email the archive with the specific heading: