Threads Flashcards

1
Q

Process

A

Programs can have many threads

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

Thread

A

Path of execution within a process

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

Every thread has its own _____, but shares memory with other threads

A

Call Stacks

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

isAlive()

A

tests if this thread is alive

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

join()

A

waits for the thread to die

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

join(long millis)

A

waits at most millis milliseconds for the thread to die

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

join(long millis, int nanos)

A

waits at most millis milliseconds plus nanos nanoseconds for the thread to die

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

3 threads created at start of Java Program

A

Main
Garbage Collector
Thread Scheduler

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

Garbage Collector

A

Daemon Thread
Intermittently removes dereferenced objects from memory
Can not force
System.gc() requests garbage collector

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

Garbage Collector: finalize()

A

Used to intervene when garbage collection occurs

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

Can Threads be garbage collected?

A

Yes, but only if it is not active

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

Synchronized

A

keyword that ensures that only one thread can access a resource at a given time

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

By synchronizing, you gain ____ but lose ___

A

Consistency, Speed

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

Thread Safe

A

one thread at a time can access

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

Thread Methods

A

start() calls run()

getPriority() values from 1 to 10

setPriority() values from 1 to 10

isAlive() checks whether the thread is running

wait() specify the amount of time to wait(can be notified)

sleep() will pause for specified amount of time(cannot be notified)

notifiy() wake up waiting threads

notifiyAll() wake up all waiting threads

join() wait for another thread to stop executing, catches up with another thread

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

Thread State: New

A

Has not started yet

17
Q

Thread State: Runnable

A

currently executing

18
Q

Thread State: Blocked

A

waiting for a lock to be released

19
Q

Thread State: Waiting

A

Thread is waiting indefinitely for another thread to perform a particular action
wait()/join() with no timeout

20
Q

Thread State: Timed_Waiting

A

Thread is waiting for a another thread to perform a particular action for a specified waiting time
sleep(), wait()/join() with timeout

21
Q

Thread State: Terminated

A

Thread completed execution, terminated

22
Q

Deadlocked

A

When multiple threads are blocking each other, trying to access the same resource

23
Q

Producer/Consumer problem

A

Starvation/Saturation
Producer: Adding data
Consumer: Removes data