0% found this document useful (0 votes)
3 views6 pages

Java Thread Assignment

This assignment challenges students to apply their knowledge of Java threads to real-life scenarios by identifying a situation with multiple simultaneous activities and proposing a solution using threads. Students must complete four parts including selecting a scenario, creating a thread mapping diagram, writing Java code, and reflecting on their design choices. The assignment emphasizes originality and understanding of concurrency concepts.

Uploaded by

silentnarrative7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Java Thread Assignment

This assignment challenges students to apply their knowledge of Java threads to real-life scenarios by identifying a situation with multiple simultaneous activities and proposing a solution using threads. Students must complete four parts including selecting a scenario, creating a thread mapping diagram, writing Java code, and reflecting on their design choices. The assignment emphasizes originality and understanding of concurrency concepts.

Uploaded by

silentnarrative7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JAVA PROGRAMMING

UNIT- 4

Creative Assignment
"Thread It into Real Life"

Assignment Type: Open-Ended Project | Max Marks: 25 | Submission: Team

Name: ___________________________ Assignment: _________________


Roll No: ________________________ Date of Submission: ______________

1. Purpose of This Assignment


You have learned how threads work — their life cycle, priorities, synchronization, and how to create
them. Now it is time to step out of the textbook and into the real world.

This assignment challenges you to think like a designer and a programmer. Instead of solving a given
problem, you identify a problem from everyday life and propose how Java threads can model or solve it.

💡 The Big Question

"Where in the world around you, are multiple things happening at the same time
— and how would you simulate that with Java threads?"

2. Sample Scenarios to Inspire You


The following examples are given only to spark your imagination. You MUST come up with your own
original idea — do not submit any of these scenarios as your answer.

⚠️Note

The scenarios below are samples for reference only. Submitting a copy or minor variation of any
example below will receive reduction in marks for originality.

🚦 SAMPLE 1 — Smart Traffic Signal

🌍 Real-world inspiration:
At a busy junction, different roads have vehicles waiting. The signal must manage each road
independently — sometimes letting an ambulance jump the queue — while a timer counts down
in the background.

🧵 How threads come in:


Each road's signal phase runs as a separate thread. A high-priority thread monitors emergency
vehicles. A timer thread counts down display seconds. A synchronization mechanism ensures
two roads are never green simultaneously.

🤖 SAMPLE 2 — AI Chatbot with Multiple Users

🌍 Real-world inspiration:
An online chatbot serves several users at once. While User A is getting a response, User B
should not have to wait for User A's session to finish.

🧵 How threads come in:


Each user session runs as a separate thread. A shared response-generator resource is
synchronized so only one thread accesses it at a time. A logging thread records all
conversations in the background without interrupting responses.
3. Your Task
Complete ALL four parts below. Each part builds on the previous one — think of it as designing a
solution step by step.

Part A — Choose Your World (5 Marks)

Identify a real-world system, process, or situation that involves multiple things happening at
the same time. It can be from:
• Your daily life (morning routine, college canteen, hostel Wi-Fi)
• Technology (games, apps, smart devices)
• Society (airports, hospitals, banks, elections)
• Nature or science (weather simulation, ant colony, human body)

Answer these questions to define your scenario:


1. What is the name of your system / scenario?
2. What are the MULTIPLE SIMULTANEOUS activities happening in it?
3. Why do these activities need to happen at the same time and not one after the
other?
4. What happens if two activities conflict or access the same resource?

Part B — Thread Mapping Diagram (6 Marks)

Draw (on paper or digitally) a Thread Mapping Diagram for your scenario. Your diagram
MUST show:
• Each thread as a labeled box (e.g., "PaymentThread", "NotificationThread")
• The priority level of each thread (LOW / NORMAL / HIGH)
• Any shared resource(s) that threads access
• Synchronization points — where threads must wait for each other
• Inter-thread communication — does one thread signal another?

Tip for Part B

Ask yourself: "Which thread is most critical and must never be delayed?" — that is your high-
priority thread. What would break if two threads accessed the same data at the same time? —
that is your synchronized zone.

Part C — Write the Java Code (10 Marks)


Implement your scenario in Java. Your code must demonstrate:
• At least 3 threads (using Thread class OR Runnable interface — your choice)
• Thread priorities set appropriately using setPriority()
• At least one synchronized method or synchronized block
• Use of sleep() to simulate real timing (e.g., a task taking 2 seconds)
• Meaningful thread names using setName()
• Console output that clearly shows which thread is doing what, and when

Bonus (up to 2 extra marks):


• Use wait() and notify() for inter-thread communication
• Handle InterruptedException gracefully with a meaningful message

Part D — Reflect and Explain (4 Marks)

Write a short reflection (150–200 words) answering these open-ended questions:

5. What would go WRONG in your system if you removed all synchronization?


6. If you had to give your scenario to the Java garbage collector as a metaphor —
which thread would it be, and why?
7. If two threads in your system were people having an argument over a shared
resource — how would they resolve it fairly?
8. What is one thing about your scenario that Java threads CANNOT model perfectly
— and what would you need instead?

Why This Matters

These questions have no single right answer. They test whether you truly understand threads
— not just how to write the code, but how to think about concurrency.

4. Open-Ended Thinking Prompts(Reference)


Stuck on an idea? Use these prompts to brainstorm. You do NOT have to answer these — they are
thinking tools.

🧠 Think about your morning... Think about construction...


Your alarm, phone charging, breakfast Electricians, plumbers, and painters all work
cooking, and someone in the shower — all on the same building. Some tasks cannot
happening in parallel. Which activity is the overlap. Who coordinates them? This is
'main thread'? What gets synchronized around synchronization in the physical world.
the bathroom?

🎮 Think about a game... 🌍 Think about the planet...


A multiplayer game renders graphics, handles Weather systems on Earth run in parallel —
player input, plays sound, and syncs with a rain in Chennai while snow falls in Kashmir.
server — all simultaneously. Which thread Could the global climate system be modeled
would crash the game if it died? as threads? What would be the shared
resource?

5. Rubric
Criterion What Excellent Work Looks Like Marks

Originality & Scenario The chosen scenario is unique, creative, and clearly from 5
Choice the student's own observation. Not a copy or trivial
variation of any sample.

Thread Mapping Diagram All threads, shared resources, priorities, and 6


synchronization zones are clearly shown. Diagram is
self-explanatory.

Java Code — Code compiles and runs. Threads are created correctly. 5
Correctness Output reflects the modeled scenario accurately.

Java Code — Thread Proper use of priorities, synchronized, sleep(), thread 5


Concepts names, and lifecycle methods. At least 3 threads
present.

Reflection Quality Answers are thoughtful and show deeper understanding. 4


Student goes beyond textbook definitions.

TOTAL 25

6. Submission Checklist
Before you submit, verify each item below:

• ☐ I chose an ORIGINAL scenario not listed in the samples


• ☐ I answered all four questions in Part A
• ☐ My Thread Mapping Diagram shows threads, priorities, shared resources, and
sync points
• ☐ My Java code has at least 3 threads
• ☐ I used setPriority() on at least one thread
• ☐ I used synchronized on at least one method or block
• ☐ I used sleep() to simulate time-based behavior
• ☐ Thread names are meaningful and set with setName()
• ☐ Console output clearly shows concurrent thread activity
• ☐ My reflection answers 4 open-ended questions in 150–200 words
• ☐ My name, roll number, and date are filled in at the top

"The best way to understand concurrency is not to read about it — it is to find it hiding in
the world around you."

Good luck — and think big! 🚀

You might also like