0% found this document useful (0 votes)
4 views4 pages

Exp14oopm A36

The document outlines a student's practical assignment on multithreading, detailing their observations, conclusions, and answers to questions about processes and threads. It includes a comparison of user threads and daemon threads, benefits of multi-threaded programming, and the lifecycle states of a thread. The student demonstrates their understanding of the subject through code examples and explanations.

Uploaded by

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

Exp14oopm A36

The document outlines a student's practical assignment on multithreading, detailing their observations, conclusions, and answers to questions about processes and threads. It includes a comparison of user threads and daemon threads, benefits of multi-threaded programming, and the lifecycle states of a thread. The student demonstrates their understanding of the subject through code examples and explanations.

Uploaded by

taff270917
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PART B

(PART B: TO BE COMPLETED BY STUDENTS)


(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded at the end of the practical)

Roll. No: 36 Name: Tanishka Gaikwad


Class: SE-A Batch: A2
Date of Experiment: 07/10/24 Date of Submission: 08/10/24
Grade:

B.1 Software Code written by student:


(Paste your code completed during the 2 hours of practical in the lab here)

B.2 Input and Output:


B.3 Observations and learning:
(Students are expected to comment on the output obtained with clear observations and
learning for each task/ sub part assigned)
Thus we have understood the multithreading concept and use of thread class for creating
different threads of a program and also by inheriting Thread class.

B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above
and learning/observation noted in section B.3)
Therefore we have created multiple threads to print $*$*$*$*$*$*.
B.5 Question of Curiosity
(To be answered by student based on the practical performed and learning/observations)

1. What is the difference between Process and Thread?

ANS:

PROCESS THREAD
1) Threads within the same process
1) Processes have their own separate share the same memory space. They
memory space. can access the same data and heap,
but each thread has its own stack
and register context.
2) Threads can communicate easily
2) Communication between processes and quickly since they share the
is more complex and slower as it same memory space. No special
often requires IPC mechanisms like mechanisms are required for
pipes, message queues, or shared threads within the same process to
memory. share data.
3) Threads have lower overhead
3) Creating and managing processes compared to processes since they
generally involve higher overhead share the same memory and
due to the allocation of separate resources.
memory and resources.

2. What are the benefits of multi-threaded programming?


ANS: a) Parallel Execution: Multi-threading allows a program to perform multiple
operations simultaneously, which can lead to better CPU utilization, especially on multi-
core systems.
b) Efficient Context Switching
c) For CPU-bound operations, multi-threading can lead to significant performance gains
by leveraging parallel processing power.
d) Some applications are naturally suited for multi-threading, such as server applications
that handle multiple client requests concurrently (e.g., web servers, database servers).

3. What is difference between user Thread and daemon Thread?


ANS:
THREAD DAEMON THREAD
1) User threads are designed to 1) Daemon threads are designed to
perform the main, active tasks provide background support
of a program. services for user threads.
2) User threads keep the Java 2) Daemon threads do not block
Virtual Machine (JVM) running the JVM from shutting down.
as long as at least one user thread
is alive.
3) Threads that handle critical 3) Threads that perform
tasks such as processing user maintenance tasks like garbage
inputs, executing business collection, file monitoring.
logic, or managing application
operations are typically user
threads

4. How can we create a Thread in Java?


ANS: In this approach, you create a new class that extends the Thread class and overrides
its run() method, which contains the code that will be executed when the thread runs.

// Creating a new class that extends Thread


class MyThread extends Thread {
@Override
public void run() {
// Code to execute when the thread starts
System.out.println("Thread is running");
}
}

public class Main {


public static void main(String[] args) {
// Creating an instance of the MyThread class
MyThread thread = new MyThread();

// Starting the thread


thread.start();
}
}

5. What are different states in lifecycle of Thread?

ANS: a) New (Newborn) State

b) Runnable (Ready/Running) State

c) Blocked/Waiting State

d) Timed Waiting State

You might also like