Threads Flashcards

1
Q

What is multithreading?

A

It is the process of executing multiple threads simultaneously to maximize the utilization of the CPU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In what ways can you create a thread?

A

Create a thread by extending a class from the Thread class or implementing the runnable interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List the methods of the Thread class and Runnable interface

A
run()
start()
sleep()
join()
getName()
setName()
setPriority()
getPriority()
stop()
resume()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the lifecycle of a thread

A

New Thread - When the thread is created but not started
Runnable - Runnable state after invocation
Running - Doing the task it was assigned
Non-Runnable/Blocked
Terminated - When the thread has completed its task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a deadlock?

A

Deadlock occurs when two threads are waiting on a locked objects from each other and can never continue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the synchronized keyword?

A

It is a keyword that allows an object to tell threads to access it one at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly