Multi-threading skills - what do you mean by that?

A while ago I mentioned the possible need of brushing up our multi-threading skills. Having said that, I cannot but share the post I came across a few years ago in the RSDN.ru forum.

Disclaimer: I am not the author of the original post, I merely translated it, hoping its content can be useful.

Lately, many Java Developer job openings started to include Java concurrency/multi-threading as one of the requirements. As a response, many developers immediately added the corresponding line to their resumes. Being the one who runs interviews, I'd like to dispel some of the misunderstanding that is related to the term.

I'd like to split all multi-threading-related projects into 3 levels: the ones that use multi-threading; the ones that are based upon multi-threading and the ones which are multi-threading itself. The first level ("the ones that use") includes projects that are meant to run in the multi-threaded enviroment. E.g., there is BlahBlahFactory class and you need to mention in the documentation, if the factory is thread-safe or not. If not, you have to make it thread-safe using ReentrantLock. The second level ("based upon") includes projects with multiple threads being used as the key components. E.g., multi-threaded H.264 video codec. The third level ("are multi-threading itself") include projects that radically change the way threads are executed. E.g., development of Scala runtime environment, using Java, lightweight threads and unique memory model.

The point is that a developer often mentions java concurrency, meaning the first level, while a company can mean the second level (development of high-performance server, development of 3D action game's physics/AI engine, OLAP system development - all those cases require several threads to process a single user request.)  Sometimes developers do not know about existence of levels other than the first one. The entry-level books contribute to that heavily.

Below you can find a list of questions from an imaginary interview about Java concurrency, covering both the first and the second level. I hope that they can be used as directions for development.

Similar to other interviews, an interviewee is not supposed to answer all questions. But it is assumed that he at least knows the topic. Moreover, it is easier to get a more complete opinion about the candidate when you understand what exactly he 1) knows, 2) heard about, 3) never heard of.

  1. Name the differrences between Collections.synchronizedMap(new HashMap()) and ConcurrentHashMap.
  2. What is the cooperative multitasking? Does Java have it? If yes, what are its advantages? If not, what kind  of multitasking does Java have?
  3. What are "green threads"? Does Java (HotSpot JVM 6) have them?
  4. What are the differences between Runnable and Callable interfaces?
  5. Write a minimal non-blocking stack (just two methods - pop() and push()).
  6. Write a minimal copy-on-write ArrayList(just four methods - void add(int index, int item), int get(int index), void remove(int index), int size()).
  7. What are the differences between Thread.isInterrupted() and Thread.interrupted()?
  8. What happens when you call Thread.interrupt()?
  9. Some of the following methods are deprecated, and some were never implemented. Which is which? Thread.interrupt(), Thread.stop(), Thread.yield(), Thread.suspend(), Thread.resume(), Thread.join(), Thread.start(), Thread.run(), Thread.sleep().
  10. What do you know about asynchronous method calls? Does Java have them? If yes, explain the implementation. If no, explain how you would implement them.
  11. Name ALL reasons that can cause InterruptedException to be thrown.
  12. What was changed between pre-Java 5 JMM and after-Java 5 NewJMM?
  13. The String class has all fields marked as final. Can we remove the final keyword, considering there are no setters and no one can re-set the fields?
  14. What is ordering, visibility, atomicity, happens-before, mutual exclusion? Please use volatile, AtomicInteger, synchronize{} to show which of them are used and in what cases.
  15. Name the differences between synchronize{} and ReentrantLock.
  16. Which methods from the list below create happens-before relationship?
    Thread.sleep(), Thread.join(), Thread.yield(), Thread.start(), Thread.run(), Thread.isAlive(), Thread.getState()
  17. What ways can you use to fight the priority inversion problem? In what kind of systems this problem is especially dangerous?
  18. What ways can you use to 1) avoid deadlocks; 2) fix deadlocks? (Imagine that you're developing RDBMS kernel.)
  19. Tell us about Reactor/Proactor patterns.
  20. What is "monitor"?
  21. What is "private mutex"?
  22. What is "priority inheritance"?
  23. What is "backoff protocol (exponential backoff)"?
  24. What is "task stealing"?
  25. What is "ABA problem"?
  26. What is "test-and-set"?
  27. What is "test-and-test-and-set"?
  28. What is "spin lock"?
  29. What is "sequential consistency"?
  30. What is "sense-reversing barrier"?
  31. What is "safe publication"?
  32. What does "reentrancy" mean?
  33. What is "recursive parallelism"?
  34. What is "iterative parallelism"?
  35. What is "pipeline architecture"?
  36. What is "poison message"?
  37. What is "mutual exclusion"? Give an example to achieve it using Java.
  38. What is "condition waiting"? Give an example to achieve it using Java.
  39. What are the advantages of SheduledThreadPool over java.util.Timer?
  40. Name the differences between java.util.concurrent.Atomic*.compareAndSwap() and java.util.concurrent.Atomic*.weakCompareAndSwap().
  41. What makes SynchronousQueue so unique among BlockingQueue implementations?
  42. What is "rendezvous"? What Java classes are needed to organize it?
  43. What is "false sharing"? Can it happen in Java? If yes, give examples and describe ways to fix it, If no, tell us how JVM developers fixed it.
  44. Thread.getState() returns a Thread.State instance. What values are possible?
  45. Write a simple limited buffer for many producers/many consumers using synchronize{}. Do it using ReentrantLock.
  46. Even if you create a ReentrantLock(true) instance, one of its method still won't respect fairness. Which one? What is the workaround?
  47. Name the most significant difference between CountDownLatch and Barrier.
  48. What do you know about Erlang? Name its important multi-threading features (which Java lacks).
  49. What do you know about CSP? Name its important multi-threading features (which Java lacks). 
  50. What is the difference between Thread.start() and Thread.run()?

Comments

Popular posts from this blog

High-volume sampling: algorithms’ comparison

Spring Framework and Code Obscurity