Concurrency III Flashcards
What is a lambda expression
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”);
What is the simplest way to ensure thread-safety
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
What is thread-safety
How do you enable thread-safety
Thread safety ensures that two threads can’t execute/access a method/object at the same time.
The key work “synchronize”
What is publishing
What is meant by an escaped object
Making an object available outside its current scope
An object that has been published but shouldn’t have been
What are the affects of declaring a variable as volatile
Tells the compiler to check the most recent write to this variable each time it’s checked.
How do you you change the state of an atomic variable
By using the atomic variable’s corresponding method
What is meant by an atomic operation
What is meant by an atomic variable
Atomic operation: program operations that run completely independent of any other processes
Atomic variable: Provides operations that can’t be interfered by multiple threads