2012-02-16

Let's Code Jumi #123: Hunting Concurrency Bugs (Part 2)

Adding the rest of the JSR-305 annotations and doing some performance testing for the thread safety checker.

Download as MP4

Episode Archive

3 comments:

  1. Curious choice to have a Set to store a single value. Isn't lastThread enough to do the checks needed?

    ReplyDelete
  2. If it is called from multiple threads, then it will throw an exception once and only once for each thread (except the first one). So it needs to remember each thread from which it was called. The test case would be: three threads call the object repeatedly (2 or more times per thread) and the expected result is that exactly two exceptions are thrown. See tests fails_at_most_once_per_thread and fails_for_each_new_thread.

    Another alternative to using a Set would be to iterate through CallLocation's causes. That would save some memory, but might make the code less readable.

    The value of lastThread alone is not enough, because it's not synchronized. It's possible that two threads read lastThread concurrently and both see it as null.

    ReplyDelete
  3. > Another alternative to using a Set would be to iterate through CallLocation's causes.

    ...if the current thread would just be stored as a field to CallLocation.

    ReplyDelete