Lab 09 - Threads

Java Concurrency - Threads, Executors, Future

Threads

Use projects  lab 1 , lab 2, lab 3

Implement the startServer and connectToServer methods in the lab.game.Level class to ensure that one instance of the game acts as the main server and other instances of the game can run in viewMode where they will not run themselves but will display the game state from the server.

Ensure that

  • all classes that will be serialized (sent through a socket) implement the Serializable interface and have a serialVersionUID.
  • all references (links) to objects that do not need to be serialized (Level, DeadListener) are marked as transient
  • the startServer method will open a ServerSocket on port 4600 and if someone connects to it (possibly multiple clients), it will use serialization and ObjectOutputStream to send objects (everything in the entities collection) to the connected client. The server will have its own thread, and each client must also have a thread to handle communication with it.
  • The connectToServer method will connect via Socket to port 4600 and will retrieve a collection of objects (entities) to be included in the world that will automatically render them.
  • Wherever you work (browse, edit) with a collection of entities, you need to ensure that the threads do not overlap, so that only one thread works with the collection at a time.

Method of submission

Submit the homework solution to the Kelvin system as the "Java 2 - Homework 1 - Maven" assignment. Upload the entire contents of the src folder and the pom.xml (and run script) file to the system. Follow the attached video below.

The project will then be compiled and Unit Tests will be performed. Due to the nature of the project and the provisional testing use of the Kelvin system in the Java 2 course, do not despair in case of failure.

This is an auxiliary test, everything will still be evaluated manually. It is important to upload the files so that everything can be evaluated and analyzed for plagiarism. I believe this is a formality and all of you are creating your own code.