title: Any satisfactory approaches to unit testing thread safety in Java?
body: <p>I am looking at improving a package that I believe not to be threadsafe when its input is shared between multiple worker threads.  According to TDD principles, I should write some tests that fail in the first instance, and these would certainly be useful in assessing the problem.</p>
  
  <p>I realise that this is not a simple thing to acheive, and that naively, multi-threaded tests will be nondeterministic as the operating system will determine scheduling and the exact order that various operations are interleaved.  I have looked at and used <a href="http://www.cs.umd.edu/projects/PL/multithreadedtc/overview.html" rel="noreferrer">MultithreadedTC</a> in the past, and this was useful.  However, in that case I knew in advance exactly where the existing implementation fell down, and thus was able to cook up a nice set of tests that covered it.</p>
  
  <p>However, if you're not at the point where you know exactly what the problem is, is there a good way of going about writing a test that stands a good chance of throwing up any potential problems?  Are there any libraries that others have found helpful? Would I be right in thinking that from a purist point of view, a multi-threaded test case should just be the same calls and assertions as the usual single-threaded test, only run with multiple worker threads as appropriate?</p>
  
  <p>Any offers on tools/best practices/philosophy in general would be welcome.</p>