Are these advanced/unfair interview questions regarding Java concurrency?
- by sparc_spread
Here are some questions I've recently asked interviewees who say they know Java concurrency:
Explain the hazard of "memory visibility" - the way the JVM can reorder certain operations on variables that are unprotected by a monitor and not declared volatile, such that one thread may not see the changes made by another thread. Usually I ask this one by showing code where this hazard is present (e.g. the NoVisibility example in Listing 3.1 from "Java Concurrency in Practice" by Goetz et al) and asking what is wrong.
Explain how volatile affects not just the actual variable declared volatile, but also any changes to variables made by a thread before it changes the volatile variable.
Why might you use volatile instead of synchronized?
Implement a condition variable with wait() and notifyAll(). Explain why you should use notifyAll(). Explain why the condition variable should be tested with a while loop.
My question is - are these appropriate or too advanced to ask someone who says they know Java concurrency?
And while we're at it, do you think that someone working in Java concurrency should be expected to have an above-average knowledge of Java garbage collection?