/Multithread-Basics

This assignment covers the basics of multithreading in Java, including subjects such as thread creation and termination, Exception handling for multithreaded programs, and an introduction to Thread Pools.

Primary LanguageJava

Multithread Basics

Sixth Assignment of Advanced Programming course at Shahid Beheshti University (Spring 2023)

Score: 110 out of 100

Introduction

In this assignment, you are given three introductory exercises focused on the basics of multithreading. Solve each exercise according to the provided guidelines.

Objectives

  • Review the concepts of multithreaded programming and utilize them correctly
  • Review the different methods of creating threads in java
  • Utilize interrupts and debug a program using them
  • Familiarize yourself with Thread Pools
  • Write a report on the assignment

Tasks

  1. Fork this repository and clone the fork to your local machine. Ensure to create a new Git branch before starting your work

  2. Complete the following exercises based on the instructions provided:

    • CPU Simulator: Simulate a single core CPU and schedule tasks to run on a thread
    • Find Multiples: write a multithreaded program to find all integers in a given range that are divisible by 3, 5, or 7. Return the sum of all unique integers.
    • Use Interrupts: Analyze the provided code and add interrupts where a thread must be terminated. Handle each interrupt in its respective thread.
  3. Commit your changes and push your commits to your fork on Github. Create a pull request (assigned to your mentor) to merge your changes to the main branch of your fork on Github.

Notes

  • You can find unit tests for the first two exercises (CPU Simulator and Find Multiples). Use these to ensure you've implemented the code correctly.
  • You are not allowed to change or delete any existing line of code in the third exercise (Use Interrupts). You can only add new code to solve the issues presented in the exercise.
  • Your report should focus on the solution you choose for each exercise (and why you chose it). Include any multithreading principles that you used in your report.

Evaluation

  • Your code should compile and run without any errors
  • Your code should be well-organized, readable, properly commented and should follow clean code principles
  • Your code should pass all of the provided unit tests
  • You should use Git for version control and include meaningful commit messages

Bonus Objectives

  1. Expand the CPU Simulator exercise by simulating a dual core CPU. Create a separate file for the new simulation. Include details of your implementation in your report.
  2. Learn how to use Thread Pools in Java and solve the Find Multiples problem using a Fixed or Cached Thread Pool. Provide adequate explanation regarding Thread Pools and the difference between using a Thread Pool and other thread creation methods.

Submission

  • Push your code to your fork on Github
  • Upload your report to your fork on GitHub

The deadline for submitting your code is Wednesday, May 3 (13th of Ordibehesht). Good luck, happy coding and hasta luego!