COMP124 Multi-Threaded Java Programming编程语言 写作

” COMP124 Multi-Threaded Java Programming编程语言 写作University of LiverpoolDepartment of Computer ScienceCOMP124 Computer SystemsCoursework 2 Multi-Threaded Java ProgrammingDeadline: Thursday 13th May at 17:00Weighting: 15%Follow the instructions below to submit your work. Penalties for late work will be applied in accordancewith the Code of Practice on Assessment. The standard department marking descriptors apply to thisassessment.IMPORTANT How to SubmitThe filename of a Java program must have the same name as the public class containing its main method.To avoid compilation Problems later on (and when we mark it) please stick to this naming scheme. If yourusername is sgnabog and your student ID is 201355426, then Your Java source file should be named sgnabog_201355426.java Your main class declaration should be public class sgnabog_201355426 { }Regardless of good programming practice, all the classes should be defined in one file. Submit just thissingle .java file containing all the classes that make up your solution (via the assessment page on Canvas).Please dont submit any other documents. We can only mark your work if we can easily locate and openthe file. You will lose marks if we have to manually change your filename to compile and run your solution.OverviewThe purpose of this assessment is to test your ability to write a compact, multi-threaded Java solutionbased on a simple producer-consumer problem. In brief Potter A produces a pot at the rate of one every 5 minutes Potter B produces a pot at the rate of one every 6 minutes After producing a pot, the potter puts it on a shelf The shelf can only store a maximum of 5 pots at any one time The packer takes pots off the shelf at a rate of one every 4 minutes The packer cannot do Any work if the shelf is empty The potters cannot make another pot until they have placed their current one on the shelfWrite a multi-threaded Java program that simulates the above scenario. You will need threads for eachpotter, and another for the packer. Your program should continue until each potter has made 10 pots andthe packer has packed all 20 pots. As the program runs, it should output a commentary on what ishappening. An example is included at the end of this document. Your output doesnt have to be identical,and in fact you will get different output each time you run your program. You can change the wording ifyou like, but the commentary must still cover all the important actions of each thread (and the shelf).Useful HintsYou need to simulate time passing, so the potters and packer can work at the speeds shown above. Thesleep() method takes a parameter representing the number of milliseconds to sleep for. This effectivelypauses the thread for that length of time. Represent each minute as 100ms, just so the program runs a bitfaster.try {sleep(500);} catch(InterruptedException e) {}The code above will simulate taking 5 minutes to make a pot, so it should be included somewhere withinthe run() method of one of the potters. The other potter should sleep for 600ms, and the packer shouldsleep for 400ms.Base your solution on the example code for the producer-consumer problem. Keep things as simple aspossible. At first, you might think that an array is a good way to represent the shelf, but this would actuallycomplicate things a lot. There is a really simple way to represent whether or not the shelf has room foranother pot, and you dont really need any parameter to the insert() method because the pots dontneed to exist as objects in the code.A good, optimal solution will be fairly small, around 100 lines depending on how many comments youinclude. If your code is significantly more than this, its an indication that youre going down the wrongpath. Remember to include All the classes for the solution in a single source file.Code Comments StructureUse the Java comment notation (comments start with // or are enclosed with /**/) to place usefulexplanations within the code. However, do not write lengthy comments that get in the way of readability.Include your student ID as a comment at the top of your code.Structure and indent your code properly, so its easy to read and understand. Use meaningful variable,class and method names. As you will be including multiple classes in the same source file, position them sothat the code is readable and makes sense from top to bottom.Note that you do not have to write and submit a report for this assessment. Submit only a single .javasource file. Therefore, make use of comments to explain briefly what your code does.Marking BreakdownYour work will be marked according to the following criteria.Style: 20% Overall layout, presentation and structure of the codeProgramming: 20% Correctness and succinctness of the codeConcurrency: 40% Efficient use of Java classes and threads to model the problemOutput: 20% Accuracy and usefulness of output as the program runsDevelopment EnvironmentWe will compile and run your solution on the command line (using the javac and java commands). Youcan use whatever Environment you like to develop your solution. As there are numerous ways to developJava code, we cannot provide technical support for anything other than basic text editor and commandlineusage.Example OutputGinny has startedHarry has startedAlbus has startedGinny is making a potHarry is making a potAlbus is ready to packShelf is empty (Waiting…)Shelf inserted a pot and now has 1 potsHarry has put a pot on the shelfHarry is making a potShelf removed a pot and now has 0 potsShelf inserted a pot and now has 1 potsGinny has put a pot on the shelfGinny is making a potAlbus has packed pot 1Albus is ready to packShelf removed a pot and now has 0 potsShelf inserted a pot and now has 1 potsHarry has put a pot on the shelfHarry is making a potShelf inserted a pot and now has 2 potsGinny has put a pot on the shelfGinny is making a potAlbus has packed pot 2Albus is ready to packShelf removed a pot and now has 1 potsShelf inserted a pot and now has 2 potsHarry has put a pot on the shelfHarry is making a potAlbus has packed pot 3Albus is ready to packShelf removed a pot and now has 1 potsShelf inserted a Pot and now has 2 potsGinny has put a pot on the shelfGinny is making a potShelf inserted a pot and now has 3 potsHarry has put a pot on the shelfHarry is making a potAlbus has packed pot 4Albus is ready to packShelf removed a pot and now has 2 potsShelf inserted a pot and now has 3 potsGinny has put a pot on the shelfGinny is making a potShelf inserted a pot and now has 4 potsHarry has put a pot on the shelfHarry is making a potAlbus has packed pot 5Albus is ready to packShelf removed a pot and now has 3 potsAlbus has packed pot 6Albus is ready to packShelf removed a pot and now has 2 potsShelf inserted a pot and now has 3 potsGinny has put a pot on the shelfGinny is making a potShelf inserted a pot and now has 4 potsHarry has put a pot on the shelfHarry is making a potAlbus has packed pot 7Albus is ready to packShelf removed a pot and now has 3 potsShelf inserted a pot and now has 4 potsHarry has put a Pot on the shelfHarry is making a potShelf inserted a pot and now has 5 potsGinny has put a pot on the shelfGinny is making a potAlbus has packed pot 8Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsHarry has put a pot on the shelfHarry is making a potAlbus has packed pot 9Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsGinny has put a pot on the shelfGinny is making a potShelf is full (Waiting…)Albus has packed pot 10Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsHarry has put a pot on the shelfHarry is making a potShelf is full (Waiting…)Albus has packed pot 11Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsGinny has put a pot on the shelfGinny is making a potShelf is full (Waiting…)Albus has packed pot 12Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot And now has 5 potsHarry has put a pot on the shelfShelf is full (Waiting…)Albus has packed pot 13Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsGinny has put a pot on the shelfGinny is making a potAlbus has packed pot 14Albus is ready to packShelf removed a pot and now has 4 potsShelf inserted a pot and now has 5 potsGinny has put a pot on the shelfAlbus has packed pot 15Albus is ready to packShelf removed a pot and now has 4 potsAlbus has packed pot 16Albus is ready to packShelf removed a pot and now has 3 potsAlbus has packed pot 17Albus is ready to packShelf removed a pot and now has 2 potsAlbus has Packed pot 18Albus is ready to packShelf removed a pot and now has 1 potsAlbus has packed pot 19Albus is ready to packShelf removed a pot and now has 0 potsAlbus has packed pot 20请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导