Demonstrating Test-Driven Development and Evolutionary Design in the long run
Adding the rest of the JSR-305 annotations and doing some performance testing for the thread safety checker.
Download as MP4
Curious choice to have a Set to store a single value. Isn't lastThread enough to do the checks needed?
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.
> 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.