3. Implement mutual exclusion with multithreading in Java Build a Java program which simulates a communication between a server and clients. You must use a thread to represent each party (as server or client). (Hint: study about the Semaphore class to perform mutual exclusion between threads) Create three threads. One thread will act as a server, which always ready to receive a message from a client (ping) and then replies the message to the same client (pong). The other two threads will become the clients, where each client will send a message to the server (ping) and waits for the reply (pong). Define 2 different classes to represent the server and the client. To perform the communication, each thread will refer to a same variable/data structure for sending and receiving the message. Use mutual exclusion approach to ensure each client can send and receive the reply without interruption from any other client(s). For this simulation, your objective is to ensure that each client must successfully send 10 pings (and thus the server must successfully perform 20 pongs) and then the program can terminate. Example output: Client 1 ping 1 Server pong 1 to client 1 client 2 ping 1 Server pong 1 to client 2 client 2 ping 2 Server pong 2 to client 2 client 1 ping 2 Server pong 2 to client 1 client 1 ping 9 Server pong 9 to client 1 Client 2 ping 9 Server pong 9 to client 2 Client 2 ping 10 Server pong 10 to client 2 Client 1 ping 10 Server pong 10 to client 1 simulation ends

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
3. Implement mutual exclusion with multithreading in Java
Build a Java program which simulates a communication between a server and clients. You
must use a thread to represent each party (as server or client). (Hint: study about the
Semaphore class to perform mutual exclusion between threads)
Create three threads. One thread will act as a server, which always ready to receive a
message from a client (ping) and then replies the message to the same client (pong). The
other two threads will become the clients, where each client will send a message to the
server (ping) and waits for the reply (pong). Define 2 different classes to represent the
server and the client.
To perform the communication, each thread will refer to a same variable/data structure for
sending and receiving the message. Use mutual exclusion approach to ensure each client
can send and receive the reply without interruption from any other client(s).
For this simulation, your objective is to ensure that each client must successfully send 10
pings (and thus the server must successfully perform 20 pongs) and then the program can
terminate.
Example output:
Client 1 ping 1
Server pong 1 to client 1
Client 2 ping 1
Server pong 1 to client 2
client 2 ping 2
Server pong 2 to client 2
Client 1 ping 2
Server pong 2 to client 1
client 1 ping 9
Server pong 9 to client 1
Client 2 ping 9
Server pong 9 to client 2
Client 2 ping 10
Server pong 10 to client 2
Client 1 ping 10
Server pong 10 to client 1
simulation ends
Transcribed Image Text:3. Implement mutual exclusion with multithreading in Java Build a Java program which simulates a communication between a server and clients. You must use a thread to represent each party (as server or client). (Hint: study about the Semaphore class to perform mutual exclusion between threads) Create three threads. One thread will act as a server, which always ready to receive a message from a client (ping) and then replies the message to the same client (pong). The other two threads will become the clients, where each client will send a message to the server (ping) and waits for the reply (pong). Define 2 different classes to represent the server and the client. To perform the communication, each thread will refer to a same variable/data structure for sending and receiving the message. Use mutual exclusion approach to ensure each client can send and receive the reply without interruption from any other client(s). For this simulation, your objective is to ensure that each client must successfully send 10 pings (and thus the server must successfully perform 20 pongs) and then the program can terminate. Example output: Client 1 ping 1 Server pong 1 to client 1 Client 2 ping 1 Server pong 1 to client 2 client 2 ping 2 Server pong 2 to client 2 Client 1 ping 2 Server pong 2 to client 1 client 1 ping 9 Server pong 9 to client 1 Client 2 ping 9 Server pong 9 to client 2 Client 2 ping 10 Server pong 10 to client 2 Client 1 ping 10 Server pong 10 to client 1 simulation ends
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY