Multi-threading Flashcards

1
Q

What is the difference between Process and Thread?

A

A process is an independent program execution unit with its own memory space, while a thread is a smaller execution unit within a process that shares the process’s memory.

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

What are the benefits of multi-threaded programming?

A

Benefits include better CPU utilization, improved application responsiveness, and the ability to perform multiple tasks concurrently.

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

What is difference between user Thread and daemon Thread?

A

User threads keep the application alive, while daemon threads are background threads that do not prevent the JVM from exiting when no user threads are running.

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

How can we create a Thread in Java?

A

A thread can be created by extending Thread or implementing Runnable and then invoking the start() method.

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

What are different states in lifecycle of Thread?

A

The thread lifecycle includes states like New, Runnable, Blocked,

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

Can we call run() method of a Thread class?

A

Yes, but calling run() directly won’t create a new thread; it will execute on the current thread.

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

How can we pause the execution of a Thread for specific time?

A

You can pause a thread using Thread.sleep(milliseconds).

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

What do you understand about Thread Priority?

A

Thread priority, between 1 and 10, influences the scheduling of threads but doesn’t guarantee the execution order.

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