Threads Flashcards

1
Q

What is a thread?

A

A lightweight process that shares code, data, and OS resources but has its own execution stack and program counter.

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

Difference between process and thread?

A

Processes have separate memory spaces; threads share memory within a process.

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

What are the advantages of multithreading?

A

Responsiveness, resource sharing, economy, scalability.

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

What is concurrency?

A

When two or more tasks start and progress over the same time period (may not be simultaneous).

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

What is parallelism?

A

True simultaneous execution of tasks on multiple cores.

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

What is the Java method to start a thread?

A

start() method.

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

In Java, where is the thread’s execution logic defined?

A

In the run() method.

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

What are the main thread states in Java?

A

NEW, RUNNABLE, RUNNING, BLOCKED, WAITING, TIMED_WAITING, TERMINATED.

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

What does join() do in Java threads?

A

It allows one thread to wait for another to finish.

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

What does yield() do in Java threads?

A

Hints the scheduler that the current thread is willing to yield CPU to other threads.

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