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
NoVisibilityexample in Listing 3.1 from "Java Concurrency in Practice" by Goetz et al) and asking what is wrong.
- Explain how
volatileaffects not just the actual variable declared
volatile, but also any changes to variables made by a thread before it changes the
- Why might you use
- Implement a condition variable with
notifyAll(). Explain why you should use
notifyAll(). Explain why the condition variable should be tested with a
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?