Concurrency III Flashcards

1
Q

What is a lambda expression

A

A block of code that can be passed between objects

Syntax: (arguments) -> {body}
Example: (int x, int y) -> {return x * y};
() -> System.out.println(“Hello”);

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

What is the simplest way to ensure thread-safety

A

Thread confinement
If a data is only used by a single thread, it’s confined
If the data doesn’t need to be shared, it should be confined

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

What is thread-safety

How do you enable thread-safety

A

Thread safety ensures that two threads can’t execute/access a method/object at the same time.
The key work “synchronize”

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

What is publishing

What is meant by an escaped object

A

Making an object available outside its current scope

An object that has been published but shouldn’t have been

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

What are the affects of declaring a variable as volatile

A

Tells the compiler to check the most recent write to this variable each time it’s checked.

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

How do you you change the state of an atomic variable

A

By using the atomic variable’s corresponding method

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

What is meant by an atomic operation

What is meant by an atomic variable

A

Atomic operation: program operations that run completely independent of any other processes

Atomic variable: Provides operations that can’t be interfered by multiple threads

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