Are these advanced/unfair interview questions regarding Java concurrency?

Posted by sparc_spread on Programmers See other posts from Programmers or by sparc_spread
Published on 2012-12-07T23:37:58Z Indexed on 2012/12/07 23:43 UTC
Read the original article Hit count: 228

Filed under:
|
|

Here are some questions I've recently asked interviewees who say they know Java concurrency:

  1. 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.
  2. 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.
  3. Why might you use volatile instead of synchronized?
  4. 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?

© Programmers or respective owner

Related posts about java

Related posts about interview