Multithreading Flashcards

1
Q

Thread vs Runnable, run() vs start()

A

In java concurrency, we have two ways to do this, first to extend Thread and second is to implement Runnable,
We should override or implement the run() method in both cases.
in order to begin the process in the new thread we need to hit the start() method.

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

Synchronization of java blocks and methods

A

In Java Synchronized keywords can be used on methods or wrap a block of codes.
It tells the compiler that one and only one thread is allowed to enter this block of code at the same time. and all variable that are used in this block will flushed and updated directly on the main memory

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

Explain usage of the couple wait()/notify()

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

Difference between sleep and wait

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

Atomic operations

A

Atomic includes both Volatile and Synchronized concepts, which means you guarantee Mutual exclusion and visibility.
The most common Atomic use cases are AtomicInteger, AtomicLong, AtomicBoolean, and AtomicReference.
Atomic have to two methods get/set which read/write from main memory, and only one thread can do it at the same time.
Another use case is compare.

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

What does it mean Volatile keyword

A

Volatile variables are never cached by processors and are read directly from the main memory.
Volatile can only implement on field declaration.
Volatile make sure that variable is visible for all threads but it’s only changeable with the responsible thread. which means other treads can’t update the variable.

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

java.util.concurrent.*, what utils do you know

A

ExecutorService: runs asynchronous tasks and manages a pool of threads; all threads belonging to the pool will be reused for new tasks;

Executor methods: newFixedThreadPool(), shutdown(), shutdownNow(), awaitTermination()

Callable and Future: we can send a test inside a Callable Function, and then assign an executor in Future. and then be able to wait for the result of the callable by calling the future.

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

Thread local, what for are they needed

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

Does child thread see the value of parent thread local

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

Deadlock definition plus example

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

Livelock definition plus example

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

Starvation definition plus example

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

Race condition definition plus example

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

Garbage definition plus example

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

Execution order

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

Atomicity of long and double assignment operations

A
17
Q

How to publish object

A
18
Q

Lock-free operations, how to create lock-free implementation of field reassignment

A
19
Q

What is Fork-Join

A
20
Q

What is Phaser (Java 7)

A