0% found this document useful (0 votes)
1 views1 page

Thread

Deadlock occurs when two threads are each waiting for a lock held by the other, causing a standstill. Monitors allow only one thread to execute a block of code at a time, while thread starvation happens when a thread lacks sufficient CPU resources. The join() method waits for a thread to finish, and the synchronized keyword ensures that only one thread can access a method at a time to prevent race conditions.

Uploaded by

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

Thread

Deadlock occurs when two threads are each waiting for a lock held by the other, causing a standstill. Monitors allow only one thread to execute a block of code at a time, while thread starvation happens when a thread lacks sufficient CPU resources. The join() method waits for a thread to finish, and the synchronized keyword ensures that only one thread can access a method at a time to prevent race conditions.

Uploaded by

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

7) What is deadlock?

Deadlock is a situation when a thread is waiting for an object lock, that is


acquired by another thread and
second thread also waiting for an object lock that is acquired by the first thread.

As both threads are waiting for each other to release this condition is called
deadlock.

9) What is a monitor?
The monitor is a body of code that can be executed by only one thread at a time.
If any other thread attempts to get access at the same time, it will be suspended
until the current thread releases the Monitor.

10) What do you mean by thread starvation?


In the situation when a thread does not have sufficient CPU for its execution
Thread starvation happens.

14) How can you pause the execution of a Thread for a certain amount of time?
sleep () method is used to pause the execution of the thread for a certain amount
of time. However, this will not stop the processing of thread for a specific time.
However, when the thread awake from sleep its state changes to runnable and based
on thread scheduling, it will be executed.

20) What join() method does?


The join() method waits for a thread to die. It forces all the running threads to
stop executing till the time the thread joins to complete its job.

24) How can multiple threads be controlled simultaneously?


Multiple threads can be simultaneously controlled if they are created in a
ThreadGroup object.

30) What is the use of Synchronized keyword?


Synchronized keyword can be applied either to the static or non-static method.
Using Synchronized only one thread can access synchronized methods. However, in
the situation where there are multiple threads which are trying to access the same
method. At that time, other threads have to wait for the execution thread.
It also provides a lock on the object to prevent a race condition.

Name three thread design patterns


1. Thread pool (Boss/Workers)
2. Peer (Work crew)
3. Pipeline

Define: critical section


The code between lock and unlock calls to a mutex.

You might also like