From 3f7a04e1e12268dcdf1f860c2aba9692ccf71326 Mon Sep 17 00:00:00 2001 From: AryanGh-imp Date: Sun, 24 May 2026 06:34:23 +0330 Subject: [PATCH] docs: Add detailed documentation for multithreading and hashing workshop --- README.md | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 255 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f40138..0869751 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,256 @@ -# WS-07-Multithreading-Basics-and-Hashing +# WS-07 – Multithreading Basics and Hashing +--- + +## Mini Student Search Engine + +### Goal + +Create a simple student search engine that: + +1. Reads students from a file +2. Processes data using multiple threads +3. Stores students inside lists +4. Supports search by ID +5. Overrides `hashCode()` and `equals()` + +--- + +## Project Structure + +``` +WS-07-Multithreading-Basics-and-Hashing/ +│ +├── students.txt +│ +├── src/main/java/dev/ +│ │ +│ ├── Main.java +│ │ +│ ├── model/ +│ │ └── Student.java +│ │ +│ ├── thread/ +│ │ └── StudentLoader.java +│ │ +│ ├── service/ +│ │ └── StudentManager.java +│ │ +│ └── utils/ +│ └── FileManager.java +│ +└── README.md +``` + +--- + +## Input File + +`students.txt` + +```txt +1001,Ali,Computer Science,3.7 +1002,Sara,Physics,3.9 +1003,John,Mathematics,3.5 +1004,Alice,Chemistry,3.2 +1005,David,Computer Science,3.8 +``` + +Format: + +```txt +id,name,major,gpa +``` + +--- + +## Part 1 – Student Class + +Create: + +```java +Student +``` + +Fields: + +```java +int id; +String name; +String major; +double gpa; +``` + +Override: + +```java +hashCode() + +equals(Object obj) + +toString() +``` + +Rules: + +Students are equal if IDs are equal. + +Example: + +```java +Student s1 = new Student(1001,...); +Student s2 = new Student(1001,...); + +s1.equals(s2); // true +``` + +Custom hash: + +```java +return id % 97; +``` + +Do NOT use: + +```java +Objects.hash() +``` + +--- + +## Part 2 – Student Loader Thread + +Create: + +```java +StudentLoader extends Thread +``` + +Each thread receives part of file lines. + +Example: + +Thread 1: + +```txt +1001 +1002 +``` + +Thread 2: + +```txt +1003 +1004 +``` + +Thread 3: + +```txt +1005 +``` + +Each thread: + +1. Reads assigned lines +2. Creates Student objects +3. Stores them in its own list + +Example: + +```java +Thread1 → listA + +Thread2 → listB + +Thread3 → listC +``` + +No shared list. + +Do NOT use: + +```java +synchronized +Lock +Semaphore +ExecutorService +``` + +--- + +# Part 3 – Merge Results + +After threads finish: + +```java +thread1.join(); +thread2.join(); +thread3.join(); +``` + +Combine results: + +```java +finalList.addAll(listA); + +finalList.addAll(listB); + +finalList.addAll(listC); +``` + +--- + +## Required Menu + +```txt +1.Load students +2.Search student +3.Remove student +4.Print students +5.Exit +``` + +Search example: + +```txt +ID:1002 + +Found: + +Student{id=1002,name=Sara} +``` + +--- + +## Restrictions + +Forbidden: + +```java +HashMap +HashSet +TreeMap +ConcurrentHashMap + +synchronized +wait() +notify() + +Lock +Semaphore + +ExecutorService +``` + +Allowed: + +```java +Thread +join() + +ArrayList + +FileReader +BufferedReader +```