

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about quiz 5 for cmsc 132, including the quiz date, format, and covered topics. The topics include threading in java, such as creating threads, thread advantages and disadvantages, and thread synchronization. Networking topics include tcp and udp, their reliability, and merits for specific applications. The document also includes exercises to help students prepare for the quiz.
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CMSC 132 Quiz 5 Worksheet
The next quiz of the course will be on Wednesday, May 2 during your lab (discussion) session. The following list provides more information about the quiz:
The following exercises cover the material to be included in this quiz. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and instructors during office hours.
Thread/Synchronization
provide a main method that creates and starts two threads, one printing the message “Testudo” and the other the message “Terps”. A third thread displaying “UMCP” will be created and started only after the previous two threads and the main thread have finished.
public class PrtMessage { private String message;
public PrtMessage(String message) { this.message = message; }
public void print() { for (int i=0; i<50; i++) System. out .println(message); }
public class MyQueue
public boolean isEmpty() { synchronized(this) { if (list.size() == 0) return true; return false; } }
public E getFirst() { synchronized(this) { return list.remove(0); // removes first element and shift // elements to the right } }
public void offer(E data) { synchronized(this) { list.add(data); } } /** If queue not empty, remove value from queue and return it.
i. Describe a possible scenario where the dequeue method will not work as documented when the dequeue is accessed by multiple threads.
ii. Modify the offer and dequeue methods in order to allow the dequeue method to wait until it can return a value when the queue is empty it (as opposed to returning null).
Networking
short, 4-byte message to machine B, and doesn’t expect to see any message in response. Discuss the merits of using TCP vs. UDP for this communication.
serverSocket.accept()). What should the server do next in order to send and receive information from the client? You do not need to write code, just indicate what the server should do.