title: Java: testing thread access to "not thread-safe" methods
body: <p>My strategy for threading issues in a Swing Java app is to divide methods in three types: </p>
  
  <ol>
  <li>methods that should be accessed by the GUI thread. These methods should never block and may call swing methods. Not thread-safe.</li>
  <li>methods that should be accessed by non-GUI threads. Basically this goes for all (potentially) blocking operations such as disk, database and network access. They should never call swing methods. Not thread-safe.</li>
  <li>methods that could be accessed by both. These methods have to be thread-safe (e.g. synchronized)</li>
  </ol>
  
  <p>I think this is a valid approach for GUI apps, where there are usually only two threads. Cutting up the problem really helps to reduce the "surface area" for race conditions. The caveat of course is that you never accidentally call a method from the wrong thread.</p>
  
  <p>My question is about testing:</p>
  
  <p>Are there testing tools that can help me check that a method is called from the right thread? I know about <code>SwingUtilities.isEventDispatchThread()</code>, but I'm really looking for something using Java annotations or aspect-oriented programming so that I don't have to insert the same boilerplate code in each and every method of the program.</p>